jeff5656 Posted August 22, 2009 Share Posted August 22, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/171438-solved-have-to-hit-delete-button-twice-for-it-to-work/ Share on other sites More sharing options...
MadTechie Posted August 22, 2009 Share Posted August 22, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/171438-solved-have-to-hit-delete-button-twice-for-it-to-work/#findComment-904102 Share on other sites More sharing options...
jeff5656 Posted August 22, 2009 Author Share Posted August 22, 2009 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/171438-solved-have-to-hit-delete-button-twice-for-it-to-work/#findComment-904107 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.