通过单击文本更改MYSQL中的值?

时间:2012-10-08 09:44:42

标签: php mysql message

我正在开展一个小型社交网络项目。到目前为止,我有一个消息系统,一切正常,用户可以发送和接收消息。我正在寻找一种方法让用户删除自己的消息。

'delete'行已设置为通过echo命令显示每条消息的一侧。 有没有办法让这个文本可以点击,以便当用户点击它时,然后将数据库中的值从“0”更改为“1”?

代码:

<?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'); ?>

2 个答案:

答案 0 :(得分:0)

使用AJAX请求在服务器端触发正确的操作。

请记住检查授权,否则可能会删除其他用户拥有的邮件。

答案 1 :(得分:0)

使用jQuery + Ajax完成类似这样的任务

$.ajax({
        type:"POST",
        url: url, // action page url
        data: "id="+id,
        success: function(msg){
        if(msg) {
              //action here     
        }
    });
相关问题