You are invited to Log in or Register a free Frihost Account!

Private message system "delete selected."

Hey, I'm doing a private message system for my site and can't quite find out how to have a user check a box and then press a button while PHP checks which ones are checked.

HTML for the buttons:

<div align="right"><input type="submit" name="delete" value="Delete Selected"> <input type="submit" name="delete" value="Delete All"></div></form>

HTML for the checkbox:

<td align='center'><input type='checkbox' name='deletem' value='$id'></td>

So, what I figured is that when you press "Delete selected" it posts all of the "deletem" numbers but all it does is get the highest number and I can't figure out why.

What am I doing wrong and how can I fix it?

I'm not an expert on this, so don't shoot me if I'm wrong ^^

I think you might have to delete them one by one using some buttons, or you could rename 'deletem' to deletem1, deletem2, because I think it overwrites all the time. I don't think its cool to have 2 inputs named the same on the same page.

Also make sure that in the next code your php script checks if the $id is actually owned by the one who is trying to delete it. It won't be hard for a passerby to just change the value with a JS injection or simply downloading the page.

<td align='center'><input type='checkbox' name='deletem' value='$id'></td>

I hope any other guys can help or correct me if I'm wrong,
To add delete buttons to all of the messages would just throw my site off, I know this way is possible cause forums do it all the time.

Also, I will secure my method, I just need to fix it before I do so. Smile

Thanks for your thoughts.
just take a look at the sourcecode of those forums then, you could just copy that.

I think they use checkboxes with an id for each pm and the "delete selected" button in in fact a submit button.
I'm just not entirely sure of how the PHP would get the ids and display the ones selected, not the highest one. I've seen on a few sites how they use "[]" in the names:


From this forums. Could that make a difference?
yeah that would make an extra layer in the array.
you'd get $_POST['id'] by using name="id"
and $_POST['id']['#'] by using name="id[]", where # is a number which starts at 0 and just increments with each addition to the array.
rvec wrote:
and $_POST['id']['#'] by using name="id[]", where # is a number which starts at 0 and just increments with each addition to the array.

Whoa, you can have two "addons" (not sure what they're called) to $_POST? If not, I believe I am slowly losing my mind.
if you use this as the name of a field : an[]example
you would use this to get the value of that field in the next script:

and if there are more places where you used the same name they will be saved here:

so in a pm script you could save all the values for one pm like this:
in the array $_POST['pm']['#']
you add 'id' with the id of the pm (in the db) as the value
you add 'delete' with a boolean value
and any other stuff you would want like move, send or rename depending on how complicated you want your system
Related topics
Windows Tips&tricks!
Laugh out loud
Yahoo shuts down private rooms
Creating an RPG bot in IRC (yes I wrote this)
Frihost Forum Rules
Help with PhpBB
Private Message Notification
SSPIMP's Graphics Shop
Joiin me Chess
.: User login systems for your site :. CHEAP AND EASY!
The new way to advertise using YouTube?
What websites do you want to see more of?
Private Message count not going down?
Does anyone now how to make a website like this?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

© 2005-2011 Frihost, forums powered by phpBB.