当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Changing Values in MYSQL By Clicking on Text?

问题描述:

I'm working on a small little social network project. So far i have a message system that all works fine, users can send and receive messages. I'm looking for a way to let users delete their own messages.

A 'delete' row has been set to display down the side of each message through an echo command.

Is there a way to make this text clickable so that when a user clicks it this then changes the value in the database from '0' to '1'?

Code:

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

网友答案:

Use AJAX request to trigger proper action on server side.

Remember to check authorization otherwise one may delete messages owned by other users.

网友答案:

Use jQuery + Ajax to do this task similar like this

$.ajax({
        type:"POST",
        url: url, // action page url
        data: "id="+id,
        success: function(msg){
        if(msg) {
              //action here     
        }
    });
分享给朋友:
您可能感兴趣的文章:
随机阅读: