Posted by Dynamo on 05/19/06 20:50
I am using values stored an $_POST array to display records from a table before
asking the user if he is sure he wants to delete them. If the user confirms then
the records are deleted. Without boring you with all of the code here is the
rough idea.
<?php
$delete = '( id = ' . implode(' OR id = ', $_POST['delete'] ) . ' ) ';
if (!isset($_POST['submit'])) {
// Then display the records that were marked for deletion
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p align="center"><font face="Arial" size="2"><b>Are you sure you wish to
continue?</b></font></p>
<p align="center"><input type="submit" name="submit" value="Yes I want to delete
these records"></p>
</form>
<?php
}
else {
$query2="DELETE FROM Catalogue WHERE $delete";
mysql_query($query2) or die("Failed Query of " . $query2);
echo "Your records were successfully deleted";
}
Everything works fine up to the point where the user confirms that he wants to
delete the records. Then I get a failed delete query message as follows:
Warning: implode(): Bad arguments. in
mywebsite\user\htdocs\deleteselectedrecords.php on line 17
Failed Query of DELETE FROM Catalogue WHERE ( id = )
Since there are no values for id I can only assume that the original array held
within $_POST['delete'] is no longer stored when the page is refreshed after the
user has confirmed that he wants to delete the records. That being the case how
can I best code the page so that I can use an array in both instances. I'm
hazarding a guess that I may have to pass the array on by using something like
<input='hidden' etc etc>. That being the case how do I do that or is there a
better way of achieving my objective?
Hope that all makes sense.
Regards
Dynamo
[Back to original message]
|