954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

The page donot load completely untill I refresh the page

Hello All,
I have this strange problem ..

I am using require function twice in a single program to call two different programs.Each one of them has their own database connections.

The page doesnot execute completely untill I hit refresh.:-/ It works as if those functions are executing one-after-the-other while I use refresh ...till then the HTML parts in the called functions appear but the mysql database values do not appear while leaving blank or previous data values in that place

Do I have to close the database connections at the end of each and every program?
I am getting the desired output only after hitting the refresh each time.

Can someone help me out with this.

Thanks in advance,

Kavitha Butchi
Junior Poster in Training
69 posts since May 2008
Reputation Points: 10
Solved Threads: 4
 

try to use require once rather than require.
are they each connectiong to a different Db?
and yes as a security flaw you should close the connection when you are finished.

casper_wang
Junior Poster in Training
89 posts since Jul 2008
Reputation Points: 13
Solved Threads: 7
 
try to use require once rather than require. are they each connectiong to a different Db? and yes as a security flaw you should close the connection when you are finished.


Hi casper_wang,
Thankyou for your time. As per your suggestions,

I changed each and every require() to require_once().

I used mysql_free_result( ) and mysql_close( ) at the end of every program.

Yes each are connecting to different databases.

Still the same problem persists.. any more suggestions will be appreciated.

Thank you.

Kavitha Butchi
Junior Poster in Training
69 posts since May 2008
Reputation Points: 10
Solved Threads: 4
 

Please Let me know if you want to have a look at the code to resolve the issue.

Kavitha Butchi
Junior Poster in Training
69 posts since May 2008
Reputation Points: 10
Solved Threads: 4
 

yes, please post the code so I and others may look for a problem in the code itself.

casper_wang
Junior Poster in Training
89 posts since Jul 2008
Reputation Points: 13
Solved Threads: 7
 

Thank you for that.. post your code as well give me a link to your site so I can see what it is doing as well.

Thank you

casper_wang
Junior Poster in Training
89 posts since Jul 2008
Reputation Points: 13
Solved Threads: 7
 

Hello All,

The code is as following:

home.php

<?php
session_start();
?>

<?php
if(isset( $_GET['userid'] ))
{
require_once('outlineget.php'); 
// calling another program which also has database connections. This is the one that is //executing after  a REFRESH and which do not execute before using a REFRESH
$userid = $_GET['userid'];
$conn=mysql_connect( ) or die ('I cannot connect to the database because: ' . mysql_error());


mysql_select_db('db1') or die (mysql_error());

$sql = "SELECT * FROM registrations WHERE userid = '$userid'";
$result1 = mysql_query("$sql") or die("Invalid query: " . mysql_error());
$row = mysql_fetch_array( $result1 );
$displayname = $row['displayname'];
$_SESSION['getdisplayname']=$displayname;

mysql_select_db('db2') or die (mysql_error());

echo '
<html>
<head>
<title>profile</title>
<style type="text/css">
// style code...
</style>
</head>';

$sql = "SELECT * FROM usersprofile WHERE displayname = '$displayname'";
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
$row = mysql_fetch_array( $result );
$profnamedb = $row['profname'];

echo '
<table id=content  border="0" cellspacing="2" cellpadding="2" >';
 echo '<tr ><td align="center"> 
                <span ><font size=4 >'.$row['displayname'].'\'s'.
'<font size=3>&nbsp&nbsp&nbsp Profile</font></span>
	     </td></tr> <br/>';
     
//....table data is displayed ...no problem here

if ($educationdb != NULL)
echo '<tr><td><font face="arial">
<div class="signupFormLftcol">Education: </div>
<div class="signupFormRgtcol" >'.$educationdb.'</div></td></tr>';

echo '</table>';
mysql_free_result($conn);
mysql_close($conn);
}

// end of home.php


outlineget.php

<?php
session_start();
?>

<?php
$conn=mysql_connect(".....") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db('db1') or die (mysql_error());

$displayname = $_SESSION['getdisplayname'];
$sql = "SELECT profilepic FROM registrations WHERE displayname = '$displayname'";
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
$row = mysql_fetch_array( $result );
$profpic = $row['profilepic'];
$_SESSION['profpic'] = $profpic;

echo '
<html>
<head>
       
<style type="text/css">

 // ...style code...

</style>
</head>

<body>

<table width="99%" border="2" cellpadding="3" cellspacing="0" BGCOLOR=A9A9A9>
<tr><td><font face="Arial" font size="2" align="center"><img src="pic1.gif"></td>
</tr>
<tr><td align="right"><font face="Arial" font size="2"><a href="home.php" class="uline">Home</a>&nbsp|&nbsp<a href="logout.php">Log out</a></td></tr>
</table>

<table width=95%>
<tr><td >
<table  width="200" border="1" cellpadding="1" cellspacing="0">
		<tr><td height="25" align="center"  BGCOLOR="A9A9A9"><font face="arial" font size="4">'.$displayname.'</td></tr>
// ... similar table data ...retreiving values from same database,table
</td></tr>
</table>
</body>
</html>
';
mysql_free_result($conn);
mysql_close($conn);
?>


This is all what the code is... reduced unnecessary length in the code.

All what happens here is ... am getting exact output only after refreshing the browser... if i do not refresh the browser the either NULL values are old data values will be present in the particular place. The problem is with OUTLINEGET.PHP part.... sometimes html part is getting displayed in it even before hitting the refresh but .. database values do not appear untill we hit refresh.

Any help :( will be appreciated.

Thankyou all in advance.

Kavitha Butchi
Junior Poster in Training
69 posts since May 2008
Reputation Points: 10
Solved Threads: 4
 

Try this:


home.php

<?php
require ('config.php');

// session_start();
$user->session_begin();

if(isset( $_GET['userid'] ))
{
require_once('outlineget.php'); 
// calling another program which also has database connections. This is the one that is //executing after  a REFRESH and which do not execute before using a REFRESH
$userid = $_GET['userid'];
// $conn=mysql_connect( ) or die ('I cannot connect to the database because: ' . mysql_error());

mysql_select_db($db1) or die ("Unable to select database!");

		$sql = 'SELECT * 
			FROM ' . registrations . "
			WHERE userid = '$userid'";
			$result = $db->sql_query($sql);
				while ($row = $db->sql_fetchrow($result))	
						{

$displayname = $row['displayname'];
$db->sql_freeresult($result);

$_SESSION['getdisplayname'] = $displayname;

mysql_select_db($db2) or die ("Unable to select database!");

echo '
<html>
<head>
<title>profile</title>
<style type="text/css">
// style code...
</style>
</head>';

		$sql = 'SELECT * 
			FROM ' . usersprofile . "
			WHERE displayname = '$displayname'";
			$result = $db->sql_query($sql);
				while ($row = $db->sql_fetchrow($result))	
						{
$profnamedb = $row['profname'];
$db->sql_freeresult($result);

echo '
<table id=content  border="0" cellspacing="2" cellpadding="2" >';
 echo '<tr ><td align="center"> 
                <span ><font size=4 >'.$row['displayname'].'\'s'.
'<font size=3>&nbsp&nbsp&nbsp Profile</font></span>
	     </td></tr> <br/>';
     
//....table data is displayed ...no problem here

if ($educationdb != NULL)
echo '<tr><td><font face="arial">
<div class="signupFormLftcol">Education: </div>
<div class="signupFormRgtcol" >'.$educationdb.'</div></td></tr>';

echo '</table>';
}
?>


outlineget.php

<?php
require ('config.php');

// $conn=mysql_connect(".....") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db('db1') or die (mysql_error());

$displayname = $_SESSION['getdisplayname'];
	$sql = ' SELECT profilepic 
		FROM ' . registrations ."
		WHERE displayname = '$displayname'";
		$result = $db->sql_query($sql);
		while ($row = $db->sql_fetchrow($result))
			{
$profpic = $row['profilepic'];
$_SESSION['profpic'] = $profpic;

echo '
<html>
<head>
       
<style type="text/css">

 // ...style code...

</style>
</head>

<body>

<table width="99%" border="2" cellpadding="3" cellspacing="0" BGCOLOR=A9A9A9>
<tr><td><font face="Arial" font size="2" align="center"><img src="pic1.gif"></td>
</tr>
<tr><td align="right"><font face="Arial" font size="2"><a href="home.php" class="uline">Home</a>&nbsp|&nbsp<a href="logout.php">Log out</a></td></tr>
</table>

<table width=95%>
<tr><td >
<table  width="200" border="1" cellpadding="1" cellspacing="0">
		<tr><td height="25" align="center"  BGCOLOR="A9A9A9"><font face="arial" font size="4">'.$displayname.'</td></tr>
// ... similar table data ...retreiving values from same database,table
</td></tr>
</table>
</body>
</html>
';
?>


create new php:
config.php

<?php
// set database server access variables: 
$host = "host_name"; 
$user = "user_name";  		//change this ti your user name
$pass = "user_password"; 	// change this to your database password
$db1 = "database_name"; 	// change tyhis to your database1 name
$db2 = "database_name"; 	// change tyhis to your database2 name

// open connection 
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 

// select database 

?>

If still having problems let me know.

casper_wang
Junior Poster in Training
89 posts since Jul 2008
Reputation Points: 13
Solved Threads: 7
 

Well, Thats because, $_SESSION['getdisplayname']=$displayname;
is being set after you include/require outlineget.php . That is, $_SESSION['getdisplayname'] is empty on the first run. So, outlineget.php will not display anything.$conn=mysql_connect(".....") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db('db1') or die (mysql_error());

$displayname = $_SESSION['getdisplayname'];
$displayname is null here. The solution is to make sure $_SESSION['getdisplayname'] has a value before you include outlineget.php.

I hope its pretty clear. Eh ?

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

yep he is correct. try this code, must have been very tired last night when I played with this.

home.php

<?php
require ('config.php');

// session_start();
$user->session_begin();

if(isset( $_GET['userid'] ))
{
$userid = $_GET['userid'];

mysql_select_db($db1) or die ("Unable to select database!");
		$sql = 'SELECT * 
			FROM ' . registrations . "
			WHERE userid = '$userid'";
			$result = $db->sql_query($sql);
				while ($row = $db->sql_fetchrow($result))	
						{
$displayname = $row['displayname'];
$db->sql_freeresult($result);

$_SESSION['getdisplayname'] = $displayname;

require ('outlineget.php'); 

mysql_select_db($db2) or die ("Unable to select database!");

echo '
<html>
<head>
<title>profile</title>
<style type="text/css">
// style code...
</style>
</head>';

		$sql = 'SELECT * 
			FROM ' . usersprofile . "
			WHERE displayname = '$displayname'";
			$result = $db->sql_query($sql);
				while ($row = $db->sql_fetchrow($result))	
						{
$profnamedb = $row['profname'];
$db->sql_freeresult($result);

echo '
<table id=content  border="0" cellspacing="2" cellpadding="2" >';
 echo '<tr ><td align="center"> 
                <span ><font size=4 >'.$row['displayname'].'\'s'.
'<font size=3>&nbsp&nbsp&nbsp Profile</font></span>
	     </td></tr> <br/>';
     
//....table data is displayed ...no problem here

if ($educationdb != NULL)
echo '<tr><td><font face="arial">
<div class="signupFormLftcol">Education: </div>
<div class="signupFormRgtcol" >'.$educationdb.'</div></td></tr>';

echo '</table>';
}
?>


outlineget.php

<?php
require ('config.php');

mysql_select_db('db1') or die (mysql_error());
	$sql = ' SELECT profilepic 
		FROM ' . registrations ."
		WHERE displayname = '$displayname'";
		$result = $db->sql_query($sql);
		while ($row = $db->sql_fetchrow($result))
			{
$profpic = $row['profilepic'];
$_SESSION['profpic'] = $profpic;

echo '
<html>
<head>
       
<style type="text/css">

 // ...style code...

</style>
</head>

<body>

<table width="99%" border="2" cellpadding="3" cellspacing="0" BGCOLOR=A9A9A9>
<tr><td><font face="Arial" font size="2" align="center"><img src="pic1.gif"></td>
</tr>
<tr><td align="right"><font face="Arial" font size="2"><a href="home.php" class="uline">Home</a>&nbsp|&nbsp<a href="logout.php">Log out</a></td></tr>
</table>

<table width=95%>
<tr><td >
<table  width="200" border="1" cellpadding="1" cellspacing="0">
		<tr><td height="25" align="center"  BGCOLOR="A9A9A9"><font face="arial" font size="4">'.$displayname.'</td></tr>
// ... similar table data ...retreiving values from same database,table
</td></tr>
</table>
</body>
</html>
';
?>


create new php:
config.php

<?php
// set database server access variables: 
$host = "host_name"; 
$user = "user_name";  		//change this ti your user name
$pass = "user_password"; 	// change this to your database password
$db1 = "database_name"; 	// change tyhis to your database1 name
$db2 = "database_name"; 	// change tyhis to your database2 name

// open connection 
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 

// select database 

?>
casper_wang
Junior Poster in Training
89 posts since Jul 2008
Reputation Points: 13
Solved Threads: 7
 

I really appreciate for your time and analysis.
Thanks a lot Casper_wang and Nav33n.

Kavitha Butchi
Junior Poster in Training
69 posts since May 2008
Reputation Points: 10
Solved Threads: 4
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You