943,522 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1967
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 2nd, 2008
0

The page donot load completely untill I refresh the page

Expand Post »
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,
Last edited by Kavitha Butchi; Jul 2nd, 2008 at 3:35 am.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Jul 2nd, 2008
1

Re: The page donot load completely untill I refresh the page

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.
Reputation Points: 13
Solved Threads: 7
Junior Poster in Training
casper_wang is offline Offline
67 posts
since Jul 2008
Jul 2nd, 2008
0

Re: The page donot load completely untill I refresh the page

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.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Jul 2nd, 2008
0

Re: The page donot load completely untill I refresh the page

Please Let me know if you want to have a look at the code to resolve the issue.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Jul 3rd, 2008
1

Re: The page donot load completely untill I refresh the page

yes, please post the code so I and others may look for a problem in the code itself.
Reputation Points: 13
Solved Threads: 7
Junior Poster in Training
casper_wang is offline Offline
67 posts
since Jul 2008
Jul 3rd, 2008
0

Re: The page donot load completely untill I refresh the page

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
Reputation Points: 13
Solved Threads: 7
Junior Poster in Training
casper_wang is offline Offline
67 posts
since Jul 2008
Jul 4th, 2008
0

Re: The page donot load completely untill I refresh the page

Hello All,

The code is as following:

home.php

php Syntax (Toggle Plain Text)
  1.  
  2. <?php
  3. session_start();
  4. ?>
  5.  
  6. <?php
  7. if(isset( $_GET['userid'] ))
  8. {
  9. require_once('outlineget.php');
  10. // 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
  11. $userid = $_GET['userid'];
  12. $conn=mysql_connect( ) or die ('I cannot connect to the database because: ' . mysql_error());
  13.  
  14.  
  15. mysql_select_db('db1') or die (mysql_error());
  16.  
  17. $sql = "SELECT * FROM registrations WHERE userid = '$userid'";
  18. $result1 = mysql_query("$sql") or die("Invalid query: " . mysql_error());
  19. $row = mysql_fetch_array( $result1 );
  20. $displayname = $row['displayname'];
  21. $_SESSION['getdisplayname']=$displayname;
  22.  
  23. mysql_select_db('db2') or die (mysql_error());
  24.  
  25. echo '
  26. <html>
  27. <head>
  28. <title>profile</title>
  29. <style type="text/css">
  30. // style code...
  31. </style>
  32. </head>';
  33.  
  34. $sql = "SELECT * FROM usersprofile WHERE displayname = '$displayname'";
  35. $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
  36. $row = mysql_fetch_array( $result );
  37. $profnamedb = $row['profname'];
  38.  
  39. echo '
  40. <table id=content border="0" cellspacing="2" cellpadding="2" >';
  41. echo '<tr ><td align="center">
  42. <span ><font size=4 >'.$row['displayname'].'\'s'.
  43. '<font size=3>&nbsp&nbsp&nbsp Profile</font></span>
  44. </td></tr> <br/>';
  45.  
  46. //....table data is displayed ...no problem here
  47.  
  48. if ($educationdb != NULL)
  49. echo '<tr><td><font face="arial">
  50. <div class="signupFormLftcol">Education: </div>
  51. <div class="signupFormRgtcol" >'.$educationdb.'</div></td></tr>';
  52.  
  53. echo '</table>';
  54. mysql_free_result($conn);
  55. mysql_close($conn);
  56. }
  57.  
  58. // end of home.php


outlineget.php

php Syntax (Toggle Plain Text)
  1.  
  2. <?php
  3. session_start();
  4. ?>
  5.  
  6. <?php
  7. $conn=mysql_connect(".....") or die ('I cannot connect to the database because: ' . mysql_error());
  8. mysql_select_db('db1') or die (mysql_error());
  9.  
  10. $displayname = $_SESSION['getdisplayname'];
  11. $sql = "SELECT profilepic FROM registrations WHERE displayname = '$displayname'";
  12. $result = mysql_query("$sql") or die("Invalid query: " . mysql_error());
  13. $row = mysql_fetch_array( $result );
  14. $profpic = $row['profilepic'];
  15. $_SESSION['profpic'] = $profpic;
  16.  
  17. echo '
  18. <html>
  19. <head>
  20.  
  21. <style type="text/css">
  22.  
  23. // ...style code...
  24.  
  25. </style>
  26. </head>
  27.  
  28. <body>
  29.  
  30. <table width="99%" border="2" cellpadding="3" cellspacing="0" BGCOLOR=A9A9A9>
  31. <tr><td><font face="Arial" font size="2" align="center"><img src="pic1.gif"></td>
  32. </tr>
  33. <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>
  34. </table>
  35.  
  36. <table width=95%>
  37. <tr><td >
  38. <table width="200" border="1" cellpadding="1" cellspacing="0">
  39. <tr><td height="25" align="center" BGCOLOR="A9A9A9"><font face="arial" font size="4">'.$displayname.'</td></tr>
  40. // ... similar table data ...retreiving values from same database,table
  41. </td></tr>
  42. </table>
  43. </body>
  44. </html>
  45. ';
  46. mysql_free_result($conn);
  47. mysql_close($conn);
  48. ?>

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.
Last edited by Kavitha Butchi; Jul 4th, 2008 at 12:03 pm.
Reputation Points: 10
Solved Threads: 4
Junior Poster in Training
Kavitha Butchi is offline Offline
69 posts
since May 2008
Jul 4th, 2008
0

Re: The page donot load completely untill I refresh the page

Try this:


home.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. require ('config.php');
  3.  
  4. // session_start();
  5. $user->session_begin();
  6.  
  7. if(isset( $_GET['userid'] ))
  8. {
  9. require_once('outlineget.php');
  10. // 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
  11. $userid = $_GET['userid'];
  12. // $conn=mysql_connect( ) or die ('I cannot connect to the database because: ' . mysql_error());
  13.  
  14. mysql_select_db($db1) or die ("Unable to select database!");
  15.  
  16. $sql = 'SELECT *
  17. FROM ' . registrations . "
  18. WHERE userid = '$userid'";
  19. $result = $db->sql_query($sql);
  20. while ($row = $db->sql_fetchrow($result))
  21. {
  22.  
  23. $displayname = $row['displayname'];
  24. $db->sql_freeresult($result);
  25.  
  26. $_SESSION['getdisplayname'] = $displayname;
  27.  
  28. mysql_select_db($db2) or die ("Unable to select database!");
  29.  
  30. echo '
  31. <html>
  32. <head>
  33. <title>profile</title>
  34. <style type="text/css">
  35. // style code...
  36. </style>
  37. </head>';
  38.  
  39. $sql = 'SELECT *
  40. FROM ' . usersprofile . "
  41. WHERE displayname = '$displayname'";
  42. $result = $db->sql_query($sql);
  43. while ($row = $db->sql_fetchrow($result))
  44. {
  45. $profnamedb = $row['profname'];
  46. $db->sql_freeresult($result);
  47.  
  48. echo '
  49. <table id=content border="0" cellspacing="2" cellpadding="2" >';
  50. echo '<tr ><td align="center">
  51. <span ><font size=4 >'.$row['displayname'].'\'s'.
  52. '<font size=3>&nbsp&nbsp&nbsp Profile</font></span>
  53. </td></tr> <br/>';
  54.  
  55. //....table data is displayed ...no problem here
  56.  
  57. if ($educationdb != NULL)
  58. echo '<tr><td><font face="arial">
  59. <div class="signupFormLftcol">Education: </div>
  60. <div class="signupFormRgtcol" >'.$educationdb.'</div></td></tr>';
  61.  
  62. echo '</table>';
  63. }
  64. ?>

outlineget.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. require ('config.php');
  3.  
  4. // $conn=mysql_connect(".....") or die ('I cannot connect to the database because: ' . mysql_error());
  5. mysql_select_db('db1') or die (mysql_error());
  6.  
  7. $displayname = $_SESSION['getdisplayname'];
  8. $sql = ' SELECT profilepic
  9. FROM ' . registrations ."
  10. WHERE displayname = '$displayname'";
  11. $result = $db->sql_query($sql);
  12. while ($row = $db->sql_fetchrow($result))
  13. {
  14. $profpic = $row['profilepic'];
  15. $_SESSION['profpic'] = $profpic;
  16.  
  17. echo '
  18. <html>
  19. <head>
  20.  
  21. <style type="text/css">
  22.  
  23. // ...style code...
  24.  
  25. </style>
  26. </head>
  27.  
  28. <body>
  29.  
  30. <table width="99%" border="2" cellpadding="3" cellspacing="0" BGCOLOR=A9A9A9>
  31. <tr><td><font face="Arial" font size="2" align="center"><img src="pic1.gif"></td>
  32. </tr>
  33. <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>
  34. </table>
  35.  
  36. <table width=95%>
  37. <tr><td >
  38. <table width="200" border="1" cellpadding="1" cellspacing="0">
  39. <tr><td height="25" align="center" BGCOLOR="A9A9A9"><font face="arial" font size="4">'.$displayname.'</td></tr>
  40. // ... similar table data ...retreiving values from same database,table
  41. </td></tr>
  42. </table>
  43. </body>
  44. </html>
  45. ';
  46. ?>

create new php:
config.php

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. // set database server access variables:
  3. $host = "host_name";
  4. $user = "user_name"; //change this ti your user name
  5. $pass = "user_password"; // change this to your database password
  6. $db1 = "database_name"; // change tyhis to your database1 name
  7. $db2 = "database_name"; // change tyhis to your database2 name
  8.  
  9. // open connection
  10. $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
  11.  
  12. // select database
  13.  
  14. ?>
If still having problems let me know.
Last edited by casper_wang; Jul 4th, 2008 at 9:50 pm.
Reputation Points: 13
Solved Threads: 7
Junior Poster in Training
casper_wang is offline Offline
67 posts
since Jul 2008
Jul 5th, 2008
1

Re: The page donot load completely untill I refresh the page

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.
Quote ...
$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 ?
Moderator
Featured Poster
Reputation Points: 524
Solved Threads: 356
Purple hazed!
nav33n is offline Offline
3,878 posts
since Nov 2007
Jul 5th, 2008
0

Re: The page donot load completely untill I refresh the page

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

home.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. require ('config.php');
  3.  
  4. // session_start();
  5. $user->session_begin();
  6.  
  7. if(isset( $_GET['userid'] ))
  8. {
  9. $userid = $_GET['userid'];
  10.  
  11. mysql_select_db($db1) or die ("Unable to select database!");
  12. $sql = 'SELECT *
  13. FROM ' . registrations . "
  14. WHERE userid = '$userid'";
  15. $result = $db->sql_query($sql);
  16. while ($row = $db->sql_fetchrow($result))
  17. {
  18. $displayname = $row['displayname'];
  19. $db->sql_freeresult($result);
  20.  
  21. $_SESSION['getdisplayname'] = $displayname;
  22.  
  23. require ('outlineget.php');
  24.  
  25. mysql_select_db($db2) or die ("Unable to select database!");
  26.  
  27. echo '
  28. <html>
  29. <head>
  30. <title>profile</title>
  31. <style type="text/css">
  32. // style code...
  33. </style>
  34. </head>';
  35.  
  36. $sql = 'SELECT *
  37. FROM ' . usersprofile . "
  38. WHERE displayname = '$displayname'";
  39. $result = $db->sql_query($sql);
  40. while ($row = $db->sql_fetchrow($result))
  41. {
  42. $profnamedb = $row['profname'];
  43. $db->sql_freeresult($result);
  44.  
  45. echo '
  46. <table id=content border="0" cellspacing="2" cellpadding="2" >';
  47. echo '<tr ><td align="center">
  48. <span ><font size=4 >'.$row['displayname'].'\'s'.
  49. '<font size=3>&nbsp&nbsp&nbsp Profile</font></span>
  50. </td></tr> <br/>';
  51.  
  52. //....table data is displayed ...no problem here
  53.  
  54. if ($educationdb != NULL)
  55. echo '<tr><td><font face="arial">
  56. <div class="signupFormLftcol">Education: </div>
  57. <div class="signupFormRgtcol" >'.$educationdb.'</div></td></tr>';
  58.  
  59. echo '</table>';
  60. }
  61. ?>

outlineget.php
PHP Syntax (Toggle Plain Text)
  1. <?php
  2. require ('config.php');
  3.  
  4. mysql_select_db('db1') or die (mysql_error());
  5. $sql = ' SELECT profilepic
  6. FROM ' . registrations ."
  7. WHERE displayname = '$displayname'";
  8. $result = $db->sql_query($sql);
  9. while ($row = $db->sql_fetchrow($result))
  10. {
  11. $profpic = $row['profilepic'];
  12. $_SESSION['profpic'] = $profpic;
  13.  
  14. echo '
  15. <html>
  16. <head>
  17.  
  18. <style type="text/css">
  19.  
  20. // ...style code...
  21.  
  22. </style>
  23. </head>
  24.  
  25. <body>
  26.  
  27. <table width="99%" border="2" cellpadding="3" cellspacing="0" BGCOLOR=A9A9A9>
  28. <tr><td><font face="Arial" font size="2" align="center"><img src="pic1.gif"></td>
  29. </tr>
  30. <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>
  31. </table>
  32.  
  33. <table width=95%>
  34. <tr><td >
  35. <table width="200" border="1" cellpadding="1" cellspacing="0">
  36. <tr><td height="25" align="center" BGCOLOR="A9A9A9"><font face="arial" font size="4">'.$displayname.'</td></tr>
  37. // ... similar table data ...retreiving values from same database,table
  38. </td></tr>
  39. </table>
  40. </body>
  41. </html>
  42. ';
  43. ?>

create new php:
config.php

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. // set database server access variables:
  3. $host = "host_name";
  4. $user = "user_name"; //change this ti your user name
  5. $pass = "user_password"; // change this to your database password
  6. $db1 = "database_name"; // change tyhis to your database1 name
  7. $db2 = "database_name"; // change tyhis to your database2 name
  8.  
  9. // open connection
  10. $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
  11.  
  12. // select database
  13.  
  14. ?>
Reputation Points: 13
Solved Threads: 7
Junior Poster in Training
casper_wang is offline Offline
67 posts
since Jul 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to insert a message board?
Next Thread in PHP Forum Timeline: PHP Paging and Page Number Nav





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC