如何在php中单击文本时将MYSQL变量值设置为1?

First off I know very little about php and am still learning so please go easy on me with your answers. Basically I'm working on a project that functions like a social network site, users are able to send and receive private messages etc. I have got this all working great and the messages even go to the messages_deleted.php page when you set the variable value from '0' to '1' in the database.

Is there a way to let the user do this themselves, to delete their own messages by clicking a piece of text?

I'm working in php so would need a piece of php code which allows me to do this if anyone has any ideas?

Here is my current php script I'm using:

<?php


    $page_title = "Messages";
        include('includes/header.php'); 

        confirm_logged_in();

        include ('includes/mod_login/login_form.php');  
    ?>

<div class="modtitle">
  <div class="modtitle-text">Inbox</div>
</div>

<div class="modcontent">

<strong>Inbox</strong> | <a href="messages_sent.php">Sent Messages</a> | <a href="messages_deleted.php">Deleted</a>
<br /><br />
<table width="100%" border="0" cellpadding="5" cellspacing="0">
  <tr bgcolor="#CCCCCC">
    <td width="30%"><strong>Recieved</strong></td>
    <td width="20%"><strong>From</strong></td>
    <td width="28%"><strong>Subject</strong></td>
    <td width="0%"><strong>Read/Unread</strong></td>
      <td width="0%"><strong>Delete</strong></td>
  </tr>
<?php
        $inbox_set = get_inbox();
        while ($inbox = mysql_fetch_array($inbox_set)) {

?>

<?php
 if ($inbox['read'] == 0) { ?>
  <tr bgcolor="#6666B3">
<?php }
 if ($inbox['read'] == 1) { ?>
    <tr>

<?php }  ?>



    <td><?php 



    $datesent1 = $inbox['date_sent'];


    echo "$datesent1"; ?></td>


    <a href="profile.php?id={$inbox['from_user_id']}"><td><?php echo "<a href=\"profile.php?id={$inbox['from_user_id']}\">{$inbox['display_name']}"; ?></td></a>

    <td><?php echo "<strong><a href=\"read_message.php?msg={$inbox[0]}\">{$inbox['subject']}</a></strong>"; ?></td>

    <td><?php   if ($inbox['read'] == 0)  {
                echo "Unread"; 
                }
                if ($inbox['read'] == 1)  {
                echo "Read";
                }
                ?></td>
                <td>
                <?php 
                if ($inbox['delete'] == 0)  {
                echo "Delete";


                }
                 if ($inbox['delete'] == 1)  {
                echo "$deleted_set;";
                }   


                    ; ?></td>



                </td>

<?php
}


?>

</tr>
</table>

</div>

<?php include('includes/footer.php'); ?>

What I really need is a way of making the 'delete' row clickable so that when a user clicks on it it sets the value to '1'. If it can be done that way it would be a lot easier for me I think.

Yes. It is quite simple. You can take a look at some basic jQuery and AJAX working on the page. Here's a link to documentation of the API.

Assumptions

If you can include jQuery to your project, then you can use PHP + AJAX to work on this. Say, you have the PHP file which makes the message deleted as messages_deleted.php. And to delete a message, I assume that, you need to pass a parameter id to the script, which finally comes this way: messages_deleted.php?id=5.

Also assuming that the code in your PHP file is:

<?php
    mysql_connect();
    if (mysql_query("UPDATE `messages` SET `deleted` = 1 WHERE `id` = " . mysql_real_escape_string($_GET["id"])))
        die ("deleted");
    else
        die ("error");
?>

Code

You can use jQuery's $.getScript() to do the work for you.

And if the message is valid and deleted, your PHP Script should die("deleted");. Adjust accordingly.

$(document).ready(function(){
    $("table tr").click(function(){
        $.getScript("messages_deleted.php", function(data){
            if (data == "deleted")
                alert("Message Deleted");
        });
    });
});

if you dont want to use Ajax, you should create a link that redirects user to a page for example delete_message.php?mid=16 where mid is the message id users wants to delete,

then on server side first check that this message belongs to the user that wants to delete it, so a user cant delete other peoples messages,

then run a mysql code whish should look like this : UPDATEmessagesSETdeleted= '1' WHEREid= '16'

i hope it helps you, let me know if you had any other questions.