Jump to content

[SOLVED] Multiple database queries from a form post


magga

Recommended Posts

Hi I have a page which lists rows from a database.

I then have a form where you can select certain rows and delete them.

What I want to do is enable users to delete multiple rows from one form which currently it is not doing.

These are the bits of code that might be useful in helping me:
[code]
$notification_id = $_POST['notification_id'];
mysql_query("DELETE from notifications where id='$notification_id'");[/code]

And from the form:
[code]<input type="checkbox" name="notification_id" value="<? echo $row['id'] ?>">[/code]
(the $id in this comes from another query and does work)

It is currently working but you can only delete one row at once obviously because the $notification_id is only holding one value on the post.

Do I need to put the values into an array then run the delete query for each value ? If so, how do I go about this ?

Thanks in advance.

Link to comment
Share on other sites

Create a "notification_id[]" field (notice brackets) for each record, that will make the field an array.

Then change you query as follows:
[code]$notification_ids = implode(",",$_POST['notification_id']);
mysql_query("DELETE FROM notifications WHERE id IN ({$notification_ids})");[/code]
Link to comment
Share on other sites

  • 1 month later...
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.