View Full Version : Reload once
I am working on a dtatbase admin for my site.
I go to add.php and add a database entry. Then I click the back button to go to the main page where it tells me how many entries in my database.
But, to see the new entry added you need to refresh the main page. How would I use php to reload the main page only once.
Jason
07-10-2003, 01:16 AM
PHP is a server side langage and stands alone so it doesn't get communication from other sources such as your DB to know if it has been updated or changed. The page will need to be updated. If from the second page you click a button to go to the front page (not the back button) then you would get the correct information. The back button just gives back the cached info in your computer. You could write a javascript that would refresh the page everytime its visited.
Jason
Jason,
your post is confusing me. I'd think that all you need to do is redirect to the main page (lets say main.php), and have a select query in main.asp.
This way, main.php will always display the correct count, and if a record was added, the count will be increased.
so
header("Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/main.php");
Would do the trick --> simply reloading main.php PHP is a server side langage and stands alone so it doesn't get communication from other sources such as your DB to know if it has been updated or changed.
Not true. For each databasequery, a result is returned to the webserver, and you should actually check for the returned value after each query (True, False, 0, 1, ... or a resource identifier --> depending on what operation you run) , to know if the rest of the script needs to be processed or if you need to abord and send an erromessage to the client.
As for inserting, you can even capture the primary key value of the record you inserted (check sticky in MySQL forum)
<edit>forum is messing up the headervalue. Should be
<?php
header("Location: http://".$_SERVER['HTTP_HOST']
.dirname($_SERVER['PHP_SELF'])
."/main.php);
?>
</edit>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.