Jump to content

MySQL DELETE


Far Cry

Recommended Posts

Hi there, I currently have this code that is supposed to delete a message according to their id. The ID is sent through a hidden input field, but it's still somehow not parsing correctly. Here it is....

$query = mysql_query("SELECT * FROM messages WHERE to_user='$username' ORDER BY message_id DESC") or trigger_error('Error: '.mysql_error()); 
        $numrows = mysql_num_rows($query);
                                if ($numrows > 0){
                                        
                                        while ($row = mysql_fetch_assoc($query)){
                                                $id = $row['message_id'];
                                                $from = $row['from_user'];
                                                $to = $row['to_user'];
                                                $title = $row['message_title'];
                                                $content = nl2br($row['message_contents']);
                                                $date = $row['date'];
											$read = $row['message_read'];

											echo"
        <center>
<table border='0' width='100%' style='text-align:center;'>
        <tr>";
	if($read == 0){
        echo"<td width='25%'><font color='white'><a href='inbox.php?action=view&mid=$id'><b>$title</b></a><b><i>NEW!</i></b></font></td>";
	}
	  else{
		  echo"<td width='25%'><font color='black'><a href='inbox.php?action=view&mid=$id'>$title</a></font></td>";
	}
        echo"<td width='25%'><font color='black'>$from</font></td>
	<td width='25%'><font color='black'>$date</font></td>
	<td width='25%'><font color='black'>
	<form action='inbox.php' method='post'>
	<input type='submit' name='delete' value='Delete' class='button'>
	<input type='hidden' name='id' value='$id'>
	</form></td>
        </tr>
        </table></center>
        <br>"; 
	if(isset($_POST['delete'])){
		$message_id = $_POST['id'];
		mysql_query("DELETE * FROM messages WHERE message_id='$message_id'");
		echo"<script type='text/javascript'>
		alert('Message deleted!')
		</script>";
	      }
                }
           }

Link to comment
Share on other sites

The following is the DELETE query syntax definition, with the most commonly use parts in red -

DELETE [LOW_PRIORITY] [QUICK] [iGNORE] FROM tbl_name

    [WHERE where_condition]

    [ORDER BY ...]

    [LIMIT row_count]

 

You need to use some error checking and error reporting logic on ALL the queries you execute in your code. You would have likely gotten an sql syntax error at the * character in your query. A DELETE query does not use a * in it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.