echo out the sql just before you execute it when doing the delete, ensure
that the values that you are expecting to be deleted are being deleted
bastien
From: "Adil" <aasheer@xxxxxxxxxxxx>
To: php-db@xxxxxxxxxxxxx
Subject: deleting multiiple records from database
Date: Wed, 13 Oct 2004 16:11:36 -0400
Hey everyone, I'm trying to delete multiple records from a database using
PHP. I have a file list page which shows each entry in the database with a
checkbox next to it. At the bottom of the page is a "Delete" button. A
user should be able to check as many items on the file list and hit delete
which would cause all checked items to be wiped from the database.
Unfortunately I'm running into really erratic behavior with this. First
the
page worked fine on Mac(in the Safari browser) but not on IE on any OS.
Now I can only delete the first time in the list but ONLY in Safari once
more.
As far as the code goes what I'm doing is retrieving each record from the
database and assigning the "value" attribute of each checkbox the unique id
from the database. From that point on, when a checkbox is checked and the
delete button is pressed, I push each checked unique id into an array and
then call a function that cycles through the array and deletes each
database
entry. The last step is a simple page refresh. I'm posting some of the
more relevant sections of the code I've used below:
echo "<form action=\"{$_SERVER['PHP_SELF']}\" method=\"post\">";
//form declaration
echo "<input type=\"submit\" value=\"Delete\"value=\"Submit\">";
//The delete button
<td><input type=\"checkbox\"
value=\"{$row['upload_id']}\"></input><br/></td>"; //This is what
the
checkbox is coded as
$stack[] = $row['upload_id']; //This should get pushed into an
array called stack when the delete button is hit(and it does when I echo it
out, so this part works)
echo "</form>";
if (isset($_POST['stack'])) {
deleteFiles(); //This checks to see if the array stack is not
empty, and if not it calls this function which is declared as shown below.
}
function deleteFiles() {
foreach($_POST['stack'] as $i) { //This should work but I can't
tell if it is or isn't
mysql_query("DELETE FROM uploads WHERE upload_id =" . "$i");
}
header("Location: http://" . $_SERVER['PHP_SELF']); //forces a
page refresh to show the file list without the items that were deleted.
}
I appreciate any help I can get on this.
Thank you
Adil.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php