Dysan Posted December 30, 2007 Share Posted December 30, 2007 The first block of code displays information from a database. Upon selecting a record using the check boxes, and after the delete button is clicked, the delete code is ran (second code block). How do I display a "Deleted Successfully" message within the first block of code, upon records deleting successfully? <?php $con = mysql_connect("localhost","peter","abc123"); if(!$con) { die(mysql_error()); } mysql_select_db("db", $con); $result = mysql_query("SELECT * FROM person"); while($row = mysql_fetch_array($result)) { echo '<input type="checkbox" name="deletePerson[]" value="' . $row['id'] . '">'; echo $row['FirstName']; echo $row['LastName'] . '<br /><br />'; } mysql_close($con); ?> <?php $delete_person = $_POST['deletePerson']; foreach($delete_person as $id) { mysql_query("DELETE FROM person WHERE id='$id'"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/83704-delete-message/ Share on other sites More sharing options...
Dane Posted December 30, 2007 Share Posted December 30, 2007 <?php $delete_person = $_POST['deletePerson']; foreach($delete_person as $id) { mysql_query("DELETE FROM person WHERE id='$id'"); echo "Deleted Successfully"; } ?> Test that Quote Link to comment https://forums.phpfreaks.com/topic/83704-delete-message/#findComment-425886 Share on other sites More sharing options...
Dysan Posted December 30, 2007 Author Share Posted December 30, 2007 How do I display the message in the first block of code, not the second? Quote Link to comment https://forums.phpfreaks.com/topic/83704-delete-message/#findComment-425889 Share on other sites More sharing options...
tibberous Posted December 30, 2007 Share Posted December 30, 2007 Move the first one below the second one. From then on, refer to it as the second one. Quote Link to comment https://forums.phpfreaks.com/topic/83704-delete-message/#findComment-425898 Share on other sites More sharing options...
Dysan Posted December 30, 2007 Author Share Posted December 30, 2007 What? I confused. Quote Link to comment https://forums.phpfreaks.com/topic/83704-delete-message/#findComment-425987 Share on other sites More sharing options...
hitman6003 Posted December 30, 2007 Share Posted December 30, 2007 Change the order of your code.... <?php /* necessary for both operations */ $con = mysql_connect("localhost","peter","abc123") or die(mysql_error()); mysql_select_db("db", $con); /* was block 2, now block 1 */ $delete_person = $_POST['deletePerson']; foreach($delete_person as $id) { mysql_query("DELETE FROM person WHERE id='$id'"); } /* was block 1, now block 2 */ $result = mysql_query("SELECT * FROM person"); while($row = mysql_fetch_array($result)) { echo ' <input type="checkbox" name="deletePerson[]" value="' . $row['id'] . '">' . $row['FirstName'] . $row['LastName'] . '<br /><br />'; } mysql_close($con); ?> Quote Link to comment https://forums.phpfreaks.com/topic/83704-delete-message/#findComment-426019 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.