Jump to content

[SOLVED] Have to hit delete button twice for it to work.


jeff5656

Recommended Posts

I want to use form to delete a record and process it on the same page as the form:

First I have the following form inside a WHILE loop that gets the records:

 

<td><form method="post" action=""><input type="hidden" value="<?php echo $row['id_incr']; ?>"name="delme" >
     <input type="submit" name="del" value="del" /></form></td>

 

And at the bottom of the page I have the processing part:



<?php
if (isset($_POST['del'])){
	$csq1 = "DELETE FROM staff WHERE id_incr = '".$_POST['delme']. "'";
	$result = mysql_query ($csq1) or die ("Invalid query: " . mysql_error ());
			 }
?>

 

It works, BUT I have to hit the delete button TWICE.  Hitting it once does not appear to do anything, then when I hit it a second time, the record gets deleted.  Anyone have any idea what is going on?

Make sure the code that has the DELETE from runs BEFORE the code that has the SELECT

 

for example

if you pull from the database then delete from it, the pull will have the data you deleted, so put the PHP code you post at the top (before the select)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.