我正在运行此查询以删除我网站上的邮件系统中的邮件,当用户点击删除时,查询运行并更新我的数据库中的表。
deleted_to is updated from '0' to '1'
我还想做的是捕获用户的id并将其存储在“user_who_deleted”列下的表中
这样做我正在使用$_SESSION['user_id']
,但我找不到将其插入表格的方法。
有人可以告诉我该怎么做。感谢
删除邮件链接代码:
<?php $inbox_set = get_inbox();
while ($inbox = mysql_fetch_array($inbox_set)) { ?>
<a href="delete_message.php?message=<?php echo $inbox['msg_id']; ?>"><div class="message_buttons2">Delete Conversation</div></a>
将deleted_to
从0设置为1的查询:
function delete_message_to($message, $user) {
global $connection;
global $_SESSION;
$query = "UPDATE ptb_messages
SET deleted_to='1'
WHERE msg_id='1' ";
mysql_query($query, $connection);
}
删除位有效,但我现在尝试将用户$_SESSION['user_id']
插入ptb_messages.user_who_deleted
如果可以的话,我想让它作为同一查询的一部分运行。我尝试了类似下面的东西,但它没有做任何事情
function delete_message_next($message, $user) {
global $connection;
global $_SESSION;
$query = "SELECT user_who_deleted
FROM ptb_messages
SET user_who_deleted =" . $_SESSION['user_id'] . "";
mysql_query($query, $connection);
}
答案 0 :(得分:0)
$query = '
UPDATE
ptb_messages
SET
deleted_to=1,
user_who_deleted = "'.$_SESSION['user_id'].'"
WHERE
msg_id=1';
理想情况下,如上所述,您希望转到mysqli或PDO,并使用预处理语句:
$query = '
UPDATE
ptb_messages
SET
deleted_to= :setDeleted,
user_who_deleted = :userId
WHERE
msg_id= :msgId';
$stmt = $dbh->prepare($query);
$stmt->bindParam(':setDeleted', 1);
$stmt->bindParam(':userId', $_SESSION['user_id']);
$stmt->bindParam(':msgId', 1);
$stmt->execute();