This is a discussion on refresh data within the PHP General forums, part of the PHP Programming Forums category; At the moment this code accepts changes and deletes from the Db but when the submit button is pressed it ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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> |
|
|||
|
Hello BigMark,
Wednesday, December 3, 2003, 6:04:03 AM, you wrote: B> At the moment this code accepts changes and deletes from the Db but when the B> submit button is pressed it echos------------- 'Record updated/edited' and i B> have to go back and refresh to view the updated list, how can i just have it B> refresh. When you open the file it shows the list but when editing it B> disappears. The problem is that you're only printing the list if there has been no editing of the database, when in actual fact you want to print the list regardless. Why not just remove this part? // this part happens if we don't press submit if (!$id) { -- Best regards, Richard mailto:rich@launchcode.co.uk |
|
|||
|
Hello BigMark,
Wednesday, December 3, 2003, 6:29:41 AM, you wrote: B> Nope that didnt work! You need to remove the fact the list is inside the check for the $submit value too. Same sentiment as before. -- Best regards, Richard mailto:rich@launchcode.co.uk |