hustler Posted October 19, 2006 Share Posted October 19, 2006 Hi i have system where registered users and admin can send messages to each other.messages is sent thru sendpm.phpand read thru readpm.phpeverything 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_idmessage_tomessage_frommessage_subjectmessagesenton Quote Link to comment Share on other sites More sharing options...
sanfly Posted October 19, 2006 Share Posted October 19, 2006 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? Quote Link to comment Share on other sites More sharing options...
hustler Posted October 19, 2006 Author Share Posted October 19, 2006 Thanx for reply, can we do it without making a seperate page for delete_pm.php? Quote Link to comment Share on other sites More sharing options...
buildakicker Posted October 19, 2006 Share Posted October 19, 2006 You could make an ADMINPM.php page. Have the delete fuction in there along with your other functions. Quote Link to comment Share on other sites More sharing options...
Skatecrazy1 Posted October 20, 2006 Share Posted October 20, 2006 wait wait waitmake 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. Quote Link to comment Share on other sites More sharing options...
sanfly Posted October 20, 2006 Share Posted October 20, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.