PDA

View Full Version : Form refresh after db updated?



Dawnshorses
10-20-2008, 02:01 AM
PHP file has these headers
<?php
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Expires: Mon. 17 Jan 2008 05:00:00 GMT");
header("Last-Modified: ". gmdate("D, F d y H:i:s"). " GMT");
include "include/session.php";
include "include/z_db.php";
session_start();
?>
Then html stuff with Form begining
<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post" >
It then pulls from the following link to db
<?php include "include/order_dbpull.inc"; $uc="UpdateCart"; ?>
Some more html and php. Then if the user clicks update
<?php
foreach($_POST as $field=>$value){

foreach($_POST['Pquantity'] as $element){
if(!is_numeric($element)){
echo "<p align='center'><font color='red' size='4'>You have entered an Invalid quantity.</font></p>";
include "include/footer4.php";
exit();
}}

if ($field == "UpdateCart") {
//updates quantity
$z=0;
$sql_q="SELECT * FROM OrderData WHERE session = '$order_number' ORDER BY Pnumber";
$resultq = mysql_query($sql_q,$link);
$_POST['Pquantity'] = array_reverse($_POST['Pquantity'], TRUE);

foreach($_POST['Pquantity'] as $field => $value){
if($z<=$cnt){
$pkn=$items[$i]['Pkey'];
$sql_quant=mysql_query("UPDATE OrderData SET Pquantity = '$value' WHERE PKey = '$pkn'");
}$z=$z+1;$i=$i-1;}
//end updates quantity code

//delete zero
$sql_d="DELETE FROM OrderData WHERE Pquantity=0 AND session = '$order_number'";
$resultd = mysql_query($sql_d,$link);
//end delete zero code
}}?>
The update works to the db but does not automatically re-display the new data. It does if you click refresh. How can i get the page to show automatically upon completion to the db?

starfish
10-20-2008, 06:14 AM
PHP file has these headers
<?php
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Expires: Mon. 17 Jan 2008 05:00:00 GMT");
header("Last-Modified: ". gmdate("D, F d y H:i:s"). " GMT");
include "include/session.php";
include "include/z_db.php";
session_start();
?>
Then html stuff with Form begining
<form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post" >
It then pulls from the following link to db
<?php include "include/order_dbpull.inc"; $uc="UpdateCart"; ?>
Some more html and php. Then if the user clicks update
<?php
foreach($_POST as $field=>$value){

foreach($_POST['Pquantity'] as $element){
if(!is_numeric($element)){
echo "<p align='center'><font color='red' size='4'>You have entered an Invalid quantity.</font></p>";
include "include/footer4.php";
exit();
}}

if ($field == "UpdateCart") {
//updates quantity
$z=0;
$sql_q="SELECT * FROM OrderData WHERE session = '$order_number' ORDER BY Pnumber";
$resultq = mysql_query($sql_q,$link);
$_POST['Pquantity'] = array_reverse($_POST['Pquantity'], TRUE);

foreach($_POST['Pquantity'] as $field => $value){
if($z<=$cnt){
$pkn=$items[$i]['Pkey'];
$sql_quant=mysql_query("UPDATE OrderData SET Pquantity = '$value' WHERE PKey = '$pkn'");
}$z=$z+1;$i=$i-1;}
//end updates quantity code

//delete zero
$sql_d="DELETE FROM OrderData WHERE Pquantity=0 AND session = '$order_number'";
$resultd = mysql_query($sql_d,$link);
//end delete zero code
}}?>
The update works to the db but does not automatically re-display the new data. It does if you click refresh. How can i get the page to show automatically upon completion to the db?

i am gaining knowledge in php-mysql, working on a project (mca final year) on the same, i am not an experienced programmer. though i would like to give u an advice if it works......
as u r executing an UPDATE query........
in the same manner u may execute a SELECT query to show the details just after the previous UPDATE query........
whenever u update or add some data in the database we can execute a select query just after it in order to show the latest updated data from the database..........
just inform...... if it works....

pghcollectibles
10-20-2008, 06:36 AM
the select thing would work.

also, if you wanted to, a javascript event could refresh the screen for you

Dawnshorses
10-20-2008, 08:47 PM
Thanks starfish. However the extra query Select did not work. I tried putting it at the end of the other stuff i'm doing. See I have the form doing a php-self print supposidly to rewrite the page which would then rerun the php script that pulled it in the first place for display.

Thanks pghcollectibles. I have this code (below) I could use but then I loose my invalid entry from the validating number because it automatically refreshes once just when you go to the page regardless of if you clicked update or not.

<script type="text/javascript">
//RELOADS page ONCE to refresh display to update database qty
window.onload = function()
{ if (!window.location.search)
{ setTimeout("window.location+='?refreshed';", .1000); } }

starfish
10-21-2008, 05:49 AM
Thanks starfish. However the extra query Select did not work. I tried putting it at the end of the other stuff i'm doing. See I have the form doing a php-self print supposidly to rewrite the page which would then rerun the php script that pulled it in the first place for display.

Thanks pghcollectibles. I have this code (below) I could use but then I loose my invalid entry from the validating number because it automatically refreshes once just when you go to the page regardless of if you clicked update or not.

<script type="text/javascript">
//RELOADS page ONCE to refresh display to update database qty
window.onload = function()
{ if (!window.location.search)
{ setTimeout("window.location+='?refreshed';", .1000); } }

i am not getting the code, the way u created php script to perform update, delete operations.....
make use of classes and functions in order to limit the code.....
it would be easy to just fetch the function to display the updated data from the database whenever it is updated......