Jump to content

Delete Message


Dysan

Recommended Posts

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'");
}

?> 

Link to comment
https://forums.phpfreaks.com/topic/83704-delete-message/
Share on other sites

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);

?> 

Link to comment
https://forums.phpfreaks.com/topic/83704-delete-message/#findComment-426019
Share on other sites

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.