Jump to content

Archived

This topic is now archived and is closed to further replies.

hustler

deleting entry from table

Recommended Posts

Hi i have system where registered users and admin can send messages to each other.

messages is sent thru sendpm.php

and read thru readpm.php

everything works fine but i need to make an option to delete the message.

How can i create a "delete" link in front of each message so that when it is pressed the message gets deleted.??

This are the fields in "messages" table:-
message_id
message_to
message_from
message_subject
message
senton

Share this post


Link to post
Share on other sites
have a link to something like "[code=php:0]delete_pm.php?id=<?=$message_id?>[/code]"

on the delete_pm page use $_GET to get the message id eg:

[code=php:0]$message_id = $_GET['id'][/code]

Then you need to have some kind of security to ensure that the person deleting the message is authorised to do so.  Perhaps compare the users id to the message_to? (Im assuming certain things about your database structure here, if you dont get what I mean then just ask me to elaborate)

Then use

[code=php:0]mysql_query("DELETE FROM messages WHERE message_id = '$message_id'")or die(mysql_error());[/code]

Is that what you were after?

Share this post


Link to post
Share on other sites
wait wait wait

make sure before you use that, put [code]LIMIT 1[/code] at the end of the query.  otherwise all of the entries in that table will be dropped.

Share this post


Link to post
Share on other sites
Sure, as a backup adding a limit is fine, but the delete query is only deleting the messages where the primary key id matches, so only one row will be deleted

Share this post


Link to post
Share on other sites

×

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.