Jump to content


Photo

deleting entry from table


  • Please log in to reply
5 replies to this topic

#1 hustler

hustler
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 19 October 2006 - 09:15 PM

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



#2 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 19 October 2006 - 09:22 PM

have a link to something like "
delete_pm.php?id=<?=$message_id?>
"

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

$message_id = $_GET['id']

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

mysql_query("DELETE FROM messages WHERE message_id = '$message_id'")or die(mysql_error());

Is that what you were after?
If you're not part of the solution, you're part of the precipitate

#3 hustler

hustler
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 19 October 2006 - 09:41 PM

Thanx for reply, can we do it without making a seperate page for delete_pm.php?

#4 buildakicker

buildakicker
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 19 October 2006 - 09:45 PM

You could make an ADMINPM.php page. Have the delete fuction in there along with your other functions.

#5 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 20 October 2006 - 02:00 AM

wait wait wait

make sure before you use that, put
LIMIT 1
at the end of the query.  otherwise all of the entries in that table will be dropped.
fuck it or fight it

#6 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 20 October 2006 - 02:16 AM

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
If you're not part of the solution, you're part of the precipitate




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users