473,770 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can not view company profile after user login: session problem??

127 New Member
The company profile showed blank after user login and click the company profile button. Supposed the company profile should not be blank and will show the company information which call from database. I use the session in login page. Thus, in the begining of companyProfile' s coding, i put session_start() ;. What is the problem of my php code?? Thanks..

[PHP]<?php
ob_start();
session_start() ;

include_once("d atabase.php");

if($_GET['ret'] == 'general' ){

//User General Information Retriving
//find the user
$general_result = mysql_query("SE LECT * FROM company WHERE username='{$_SE SSION['username']}'")
or die(mysql_error ());
$general_row = mysql_fetch_arr ay( $general_result ); //set $row to result

//table to display general user inforamtion
echo "<hr><table width=100% border=0>
<tr>
<td><div align=center>
<img src= width=100 height=100>
</div></td>
</tr>
<tr>
<td><table width=70% border=0 align=center>
<tr>
<td width=40% ><font face=Arial size=2>Company Name</font></td>
<td width=2%>:</td>
<td width=58%>" . $general_row['companyName'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>Company Type</font></td>
<td>:</td>
<td>" . $general_row['companyType'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>Contact Name</font></td>
<td>:</td>
<td>" . $general_row['contactName'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>Descript ion</font></td>
<td>:</td>
<td>" . $general_row['description'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>Username </font></td>
<td>:</td>
<td>" . $general_row['username'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>Password </font></td>
<td>:</td>
<td>" . $general_row['password'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>Email Address</font></td>
<td>:</td>
<td>" . $general_row['emailAdd'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>ContactN umber</font></td>
<td>:</td>
<td>" . $general_row['contactNum'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>Fax</font></td>
<td>:</td>
<td>" . $general_row['fax'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>Contact Addresss</font></td>
<td>:</td>
<td>" . $general_row['contactAddress '] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>City </font></td>
<td>:</td>
<td>" . $general_row['city'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>Postcode </font></td>
<td>:</td>
<td>" . $general_row['postcode'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>State</font></td>
<td>:</td>
<td>" . $general_row['state'] . "</td>
</tr>
<tr>
<td><font face=Arial size=2>Country</font></td>
<td>:</td>
<td>" . $general_row['country'] . "</td>
</tr>
</table></td>
</tr>
</table><br><br>" ;



}//end selection on general information retriving


?>[/PHP]
Feb 1 '07
15 2293
bb nicole
127 New Member
The only reason I can see for not seeing anything is that your first test:
if($_GET['ret'] == 'general')
isn't succeeding.


Emm... I have change the code but still cannot function...
Do you have any idea, motoma??? Thanks..
Feb 5 '07 #11
Motoma
3,237 Recognized Expert Specialist
In your code you have this:
[PHP]
echo"...
[/PHP]

There is no space between echo and "
Try this:

[PHP]
echo "...
[/PHP]

Boy, I will be upset if that solves it.
Feb 5 '07 #12
Atli
5,058 Recognized Expert Expert
If your using php 5.2.0.
by default, no error reports will be shown.

Try adding this to the top of you code and run the script. It will show all errors and warning. Might help you identify your problem.

[PHP]error_reporting (E_ALL);[/PHP]

I did most likely find the error tho.

Switch ob_start(); and session_start() ;
session_start() ; should always be the top line of your code, unless you have a good reason not to. Its just good practice.

Add ob_end_flush(); to the bottom of your code.
This ends the output buffering and sends the buffer to the browser. Tho this shouldn't be required it seemes not closing the buffer interferes with the database connection in a weird way.
I always close ob_start() with ob_end_flush(). It just doesnt feel right to leave the buffer hanging like that.
Feb 5 '07 #13
bb nicole
127 New Member
Thanks, Motoma... Thanks, Alti... I have try many way, but still can't work... I don't know wheather is my login function got error or what, it still can't work... And after i add [PHP]<?error_reporti ng(E_ALL);?>[/PHP], the error message as below:
Notice: Undefined variable: company_ID in C:\Apache2\Apac he2\htdocs\comp anyProfile.php on line 14
which line 14 is
[PHP]<? $sql =mysql_query("S ELECT * FROM company WHERE company_ID='{$_ SESSION['company_ID']}'"); ?>[/PHP]
Below is my modify code for company profile and login, what is happening, i want to give up ledy...
company profile
[PHP]<?php
error_reporting (E_ALL);
session_start() ;
ob_start();

//connect to server and select database

$conn=mysql_con nect("localhost ", "root", "") or die (mysql_error()) ;
mysql_select_db ("ums e-job portal", $conn) or die(mysql_error ());



// construct SQL statement
$sql =mysql_query("S ELECT * FROM company WHERE company_ID='{$_ SESSION['company_ID']}'");




?>

<div align='center'> <font face='Arial' size='3'><stron g>Company Profile</strong></font></div>
<table width='88%' border='1'>
<tr>

<?
while($rows=mys ql_fetch_array( $sql)){
?>


<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Compan y Name</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['companyName'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Compan y Type</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo$rows['companyType'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Contac t Name</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['contactName'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Descri ption</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['description'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Userna me</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['username'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Passwo rd</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['password'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Email Address</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['emailAdd'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Contac tNumber</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['contactNum'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Fax</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['fax'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Contac t Addresss</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Verdana' size='2'><? echo $rows['contactAdd'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>City</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['city'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Postco de</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['postcode'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>State</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['state'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E 8'>&nbsp;<font face='Arial' size='2'>Countr y</strong></td>
<td width=73% align=center bgcolor='#f1f1f 1'>&nbsp;<font face='Arial' size='2'><? echo $rows['country'];?></strong></td>
</tr>

</table>


<?

}


ob_end_flush();
?>[/PHP]

Login
[PHP]<?php
ob_start();
session_start() ;

extract ($_POST);

mysql_connect(" localhost","roo t","")
or die("Cannot connect to the server");

mysql_select_db ("ums e-job portal")
or die("Cannot connect to the database");

$_SESSION['loggedin'] = 1;

$sql="select username from company where username='$user name'";

$result=mysql_q uery($sql)
or die("Cannot execute query");

$num=mysql_num_ rows($result);


if($num==1) //username valid
{
$sql="select username from company where username='$user name' and password='$pass word'";

$result2=mysql_ query($sql)
or die("Cannot execute query");

$num2=mysql_num _rows($result2) ;
if($num2>0)
{
$_SESSION['loggedin'] = 1;
$_SESSION['loggedin'] = time();
$_SESSION['username'] = $username;
$_SESSION['company_ID'] = $company_ID;

include("welcom e.php");

exit();
}
else //message send to emp_login.php when wrong password
{
$message="The username, $username exists, but you have not entered the correct password! Please try again.<br>";
include("emp_lo gin.php");
}
}


else
$_SESSION['loggedin'] = 0;
//message send to emp_login.php when username not valid
{
$message="The username you entered does not exist! Please try again.<br>";
include("emp_lo gin.php");
}



?>[/PHP]
Feb 6 '07 #14
Atli
5,058 Recognized Expert Expert
The $_SESSION['company_ID'] variable isnt set, so the query is looking for an empty string and naturally returns nothing.

It is most likely this line in the code.
[PHP]$_SESSION['company_ID'] = $company_ID;[/PHP]
Make sure the $company_ID is set correctly where ever it is you set it.
Feb 7 '07 #15
bb nicole
127 New Member
The $_SESSION['company_ID'] variable isnt set, so the query is looking for an empty string and naturally returns nothing.

It is most likely this line in the code.
[PHP]$_SESSION['company_ID'] = $company_ID;[/PHP]
Make sure the $company_ID is set correctly where ever it is you set it.



Thanks..
I know what you means..:)
Feb 10 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

3
3656
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore my settings if my profile became tampered with or corrupt. Is there any sample code available out there? -Robert
4
1467
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore my settings if my profile became tampered with or corrupt. Is there any sample code available out there? -Robert
0
2400
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile View I want the form populated from there profile on the sql server. The code to save the profile works fine. But when the user logs back in they data doesn't load back to the form. The multiview is located inside the LoginView's Logged-In View ....
1
3547
by: Rusty Hill | last post by:
My site does not allow anonymous users. After a user has logged in and been authenticated I need to access some information in their profile object. I thought I would do this in the LoggedIn event of the Login object but when that event fires the user is still not authenticated so the profile is null. Where and how should I be doing this? Should I be checking the ProfileModule.MigrateAnonymous Event in the global.asax? Remember I do...
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.