Jump to content

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


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)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.