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
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
Share on other sites

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.