refresh data

From: Date: Wed, 03 Dec 2003 06:04:03 +0000
Subject: refresh data
Groups: php.general 
Request: Send a blank email to php-general+get-171641@lists.php.net to get a copy of this message
At the moment this code accepts changes and deletes from the Db but when the submit button is pressed it echos------------- 'Record updated/edited' and i have to go back and refresh to view the updated list, how can i just have it refresh. When you open the file it shows the list but when editing it disappears. <html> <?php $db = mysql_connect("localhost", "root"); mysql_select_db("mydb",$db); if ($submit) { // here if no ID then adding else we're editing if ($id) { $sql = "UPDATE employees SET first='$first',last='$last' WHERE id=$id"; } else { $sql = "INSERT INTO employees (first,last) VALUES ('$first','$last')"; } // run SQL against the DB $result = mysql_query($sql); echo "Record updated/edited!<p>"; } elseif ($delete) { // delete a record $sql = "DELETE FROM employees WHERE id=$id"; $result = mysql_query($sql); echo "$sql Record deleted!<p>"; } else { // this part happens if we don't press submit if (!$id) { // print the list if there is not editing $result = mysql_query("SELECT * FROM employees",$db); while ($myrow = mysql_fetch_array($result)) { printf("<ahref=\"%s?id=%s\">%s- V - %s......</a>\n", $PHP_SELF, $myrow["id"], $myrow["first"],$myrow["last"]); printf("<a href=\"%s?id=%s&delete=yes\">(DELETE)</a><br>", $PHP_SELF, $myrow["id"]); } } ?> <P> <br> <P> <form method="post" action="<?php echo $PHP_self?>"> <?php if ($id) { ?> <input type=hidden name="id" value="<?php echo $id ?>"> <?php } ?> Team A:<input type="Text" name="first" value="<?php echo $first?>"> <br><br> Team B:<input type="Text" name="last" value="<?php echo $last ?>"><br><br> <input type="Submit" name="submit" value="Enter Team Names"> </form> <?php } ?> </body> </html>

« previous php.general (#171641) next »