By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,043 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,043 IT Pros & Developers. It's quick & easy.

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

100+
P: 127
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("database.php");

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

//User General Information Retriving
//find the user
$general_result = mysql_query("SELECT * FROM company WHERE username='{$_SESSION['username']}'")
or die(mysql_error());
$general_row = mysql_fetch_array( $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>Description</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>ContactNumber</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 #1
Share this Question
Share on Google+
15 Replies


Motoma
Expert 2.5K+
P: 3,235
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("database.php");

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

//User General Information Retriving
//find the user
$general_result = mysql_query("SELECT * FROM company WHERE username='{$_SESSION['username']}'")
or die(mysql_error());
$general_row = mysql_fetch_array( $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>Description</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>ContactNumber</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]

Not sure...It could very well depend on what is inside the database.php file. Have you put echos inside your if statement to make sure you are in fact getting in there?
Feb 1 '07 #2

100+
P: 127
I know what you are talking about... The database.php is just connect to server and database.
If i delete
[PHP]include_once("database.php");[/PHP]
and add
[PHP]//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die (mysql_error());
mysql_select_db("ums e-job portal",$conn) or die(mysql_error());[/PHP]

The result also same, it will display the blank page...
What is the problem??
Thanks..
Feb 1 '07 #3

Motoma
Expert 2.5K+
P: 3,235
I know what you are talking about... The database.php is just connect to server and database.
If i delete
[PHP]include_once("database.php");[/PHP]
and add
[PHP]//connect to server and select database
$conn = mysql_connect("localhost", "root", "")
or die (mysql_error());
mysql_select_db("ums e-job portal",$conn) or die(mysql_error());[/PHP]

The result also same, it will display the blank page...
What is the problem??
Thanks..
Put an echo inside your if() block to see if you are getting in there.
Feb 1 '07 #4

100+
P: 127
Sorry.. I don't really understand what you said... I already put echo inside the if() statement as below to dispaly the company profile, is it like this??
[PHP]<?
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>Description</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>ContactNumber</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>";

?>[/PHP]
Feb 1 '07 #5

100+
P: 127
Can anyone help??? What is the problem with my coding??? Why it is a blank page after click inside it???
Feb 2 '07 #6

Motoma
Expert 2.5K+
P: 3,235
Can anyone help??? What is the problem with my coding??? Why it is a blank page after click inside it???
The only reason I can see for not seeing anything is that your first test:
if($_GET['ret'] == 'general')
isn't succeeding.
Feb 2 '07 #7

100+
P: 127
Thanks, i will try to look at it... :)
Feb 2 '07 #8

100+
P: 127
I try to edit my company profile, which the user can view their profile after they login... But it still show the blank page... But when i move it outside the htdocs and press F12, it will show the table... And i try to check it one by one, which means i try to cut the interface out, and it able display the interface... Emm.. I really don't what is the problem... Thanks... Below is my coding for company profile...

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

//connect to server and select database

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


// construct SQL statement
$sql = mysql_query("SELECT * FROM company WHERE company_ID='{$_SESSION['company_ID']}'");

while($rows=mysql_fetch_array($sql)){

//table to display company profile

echo" <div align='center'><font face='Arial' size='3'><strong>Company Profile</strong></font></div>
<table width='48%' border='1'>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Company Name</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['companyName']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Company Type</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['companyType']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Contact Name</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['contactName']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Description</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['description']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Username</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['username']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Password</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['password']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Email Address</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['emailAdd']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>ContactNumber</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['contactNum']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Fax</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['fax']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Contact Addresss</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Verdana' size='2'>{$rows['contactAdd']}</strong></td>
</tr>]

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>City</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['city']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Postcode</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['postcode']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>State</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['state']}</strong></td>
</tr>

<tr>
<td width=27% align=left bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Country</strong></td>
<td width=73% align=left bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'>{$rows['country']}</strong></td>
</tr>

</table>";

}


//end selection on general information retriving


?>
[/PHP]
Feb 4 '07 #9

100+
P: 127
Hi... Is it anyone have an idea how to edit or repair my code, i really no idea...
Emm... i think the code is correct, but don't why the result is the blank page..
It doesn't show any error... Is it the coding can't get the user id from database?
Feb 4 '07 #10

100+
P: 127
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
Expert 2.5K+
P: 3,235
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
Expert 5K+
P: 5,058
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

100+
P: 127
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_reporting(E_ALL);?>[/PHP], the error message as below:
Notice: Undefined variable: company_ID in C:\Apache2\Apache2\htdocs\companyProfile.php on line 14
which line 14 is
[PHP]<? $sql =mysql_query("SELECT * 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_connect("localhost", "root", "") or die (mysql_error());
mysql_select_db("ums e-job portal", $conn) or die(mysql_error());



// construct SQL statement
$sql =mysql_query("SELECT * FROM company WHERE company_ID='{$_SESSION['company_ID']}'");




?>

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

<?
while($rows=mysql_fetch_array($sql)){
?>


<td width=27% align=center bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Company Name</strong></td>
<td width=73% align=center bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'><? echo $rows['companyName'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Company Type</strong></td>
<td width=73% align=center bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'><? echo$rows['companyType'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Contact Name</strong></td>
<td width=73% align=center bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'><? echo $rows['contactName'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Description</strong></td>
<td width=73% align=center bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'><? echo $rows['description'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Username</strong></td>
<td width=73% align=center bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'><? echo $rows['username'];?></strong></td>
</tr>

<tr>
<td width=27% align=center bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Password</strong></td>
<td width=73% align=center bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'><? echo $rows['password'];?></strong></td>
</tr>

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

<tr>
<td width=27% align=center bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>ContactNumber</strong></td>
<td width=73% align=center bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'><? echo $rows['contactNum'];?></strong></td>
</tr>

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

<tr>
<td width=27% align=center bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Contact Addresss</strong></td>
<td width=73% align=center bgcolor='#f1f1f1'>&nbsp;<font face='Verdana' size='2'><? echo $rows['contactAdd'];?></strong></td>
</tr>

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

<tr>
<td width=27% align=center bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Postcode</strong></td>
<td width=73% align=center bgcolor='#f1f1f1'>&nbsp;<font face='Arial' size='2'><? echo $rows['postcode'];?></strong></td>
</tr>

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

<tr>
<td width=27% align=center bgcolor='#E8E8E8'>&nbsp;<font face='Arial' size='2'>Country</strong></td>
<td width=73% align=center bgcolor='#f1f1f1'>&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","root","")
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='$username'";

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

$num=mysql_num_rows($result);


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

$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("welcome.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_login.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_login.php");
}



?>[/PHP]
Feb 6 '07 #14

Atli
Expert 5K+
P: 5,058
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

100+
P: 127
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

Post your reply

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