0

So right now I am coding so users can delete their messages by checking the ones they want to delete and hit the delete button.

But then my problem occurs, how do I delete more then one entry with only one query?

Like, if it was radio buttons I could delete one entry matching the right one with $_POST['radio'] but now it can be only one entry and it can be more entries.

I'm sorry if it is hard to understand my problem, I'll try to explain better if you don't get it.

Hannes
  • 8,147
  • 4
  • 33
  • 51
Joakim Melin
  • 175
  • 1
  • 2
  • 6

2 Answers2

2

Make an array of checkboxes with the message id. The HTML notation is like this.

<input name="del[1]"
<input name="del[2]"
etc...

Then iterate over $_POST['del'] to find the messages id(s) to delete.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Ray Paseur
  • 2,106
  • 2
  • 13
  • 18
1

All I can think of is using a script on the user side and concatenate a string to the post. You can use document.getElementById and get its values by creating all your check boxes inside a div with id or give your boxes directly the id.

Let me try to explain my self: In $_POST['checkboxes'] you would get a string divided by a known/selected by you character that you can split into a vector of strings with php's explode().

The concatenation, though, should be done by script on the user side.

Imagine you have the box with value hello, and the box with value world. What you'll have to do is instead of action="submit" on your form, you'll have something like action="someJSFunction". This function should get all the checked boxes values in one string: String a += document.getElementById.value; (or something like this) and then your function makes the submit. If those two example boxes were set and you'd chosed the \ character as division, in your php $_POST['checkboxes'] you'll get: hello\world.

If you want to keep your form action with submit, make your delete button type as submit and onclick make it call your function but with return false so it waits for the end of the script to sumbmit. Something like: onclick"someFunc(this); return false"

I had this problem some time ago and this was the way I solved it.

Hope this helps.

Afonso Tsukamoto
  • 1,184
  • 1
  • 12
  • 21