gpt4 book ai didi

php - 收件箱、发件箱删除错误 - 请帮助我

转载 作者:行者123 更新时间:2023-11-29 08:05:54 28 4
gpt4 key购买 nike

我有一个用于删除邮件的收件箱代码。

如果我选择一条消息,它将删除所有消息。

我该如何解决这个问题?

这是我的delete_message.php代码:

<?php
$inboxbtn = $_POST['deleteinbox'];
$outboxbtn = $_POST['deleteoutbox'];

if ($inboxbtn)
{
$selectall = $_POST['selectall'];
if ($selectall)
{
$query = mysql_query("SELECT * FROM messages WHERE to_user='$user'");
while ($row = mysql_fetch_assoc($query))
{
mysql_query("UPDATE messages SET to_delete='1' WHERE to_user='$user'");
}

echo "All messages have been deleted.";
}
else
{
$query = mysql_query("SELECT * FROM messages WHERE to_user='$user'");
while ($row = mysql_fetch_assoc($query))
{
$msg_id = $row['id'];
$value = "cb" . "$msg_id";
$checkbox = $_POST[$value];
if ($value)
{
mysql_query("UPDATE `messages` SET `to_delete`='1' WHERE `to_user`='$user' AND `id`='$msg_id'");
}
}

echo "The selected messages have been deleted.";
}
}
elseif ($outboxbtn)
{
$selectall = $_POST['selectall'];
if ($selectall)
{
$query = mysql_query("SELECT * FROM messages WHERE from_user='$user'");
while ($row = mysql_fetch_assoc($query))
{
mysql_query("UPDATE messages SET from_delete='1' WHERE from_user='$user'");
}

echo "All messages have been deleted.";
}
else
{
$query = mysql_query("SELECT * FROM messages WHERE from_user='$user'");
while ($row = mysql_fetch_assoc($query))
{
$msg_id = $row['id'];
$value = "cb" . "$msg_id";
$checkbox = $_POST[$value];
if ($value)
{
mysql_query("UPDATE messages SET from_delete='1' WHERE to_user='$user' AND id='$msg_id'");
}
}

echo "The selected messages have been deleted.";
}
}
else echo "Choose a message to delete.";
?>

这是 inbox.php 中带有复选框的代码

<?php
$query = mysql_query("SELECT * FROM messages WHERE from_user='$user' AND from_delete='0' ORDER BY id DESC");
$numrows = mysql_num_rows($query);

if ($numrows != 0)
{
echo "<form action='delete_message.php' method='POST'>";
echo "<div class='messages'>
<div class='leftside'><input type='checkbox' name='selectall'><input type='submit' name='deleteoutbox' value='Delete' class'button'></div>
<div class='rightside'>Date</div>
Subject And Message
<div class='clear'></div>
<hr>
</div>";
while ($row = mysql_fetch_assoc($query))
{
$msg_id = $row['id'];
$msg_to_user = $row['to_user'];
$msg_to_id = $row['to_id'];
$msg_from_user = $row['from_user'];
$msg_from_id = $row['from_id'];
$msg_subject = $row['subject'];
$content = nl2br($row['content']);
$msg_date = $row['date'];
$msg_from_delete = $row['from_delete'];
$msg_to_delete = $row['to_delete'];
if (!$msg_from_delete)
{
echo "<div class='messages'>";
echo "<div class='leftside'>
<input type='checkbox' name='cb$msg_id' value='$msg_id'>
<a href='profile.php?id=$msg_to_id' target='_blank'>$msg_to_user</a>
</div>";
echo "<div class='rightside'>$msg_date</div>";
echo "<div id='center' style='margin-left:150px; margin-right:150px;'>

<span class='toggle'><a href='#' onClick='return false'>$msg_subject</a></span>
<div class='hiddenDiv'>
<br /><hr>
<b>$smiles </b>
<br /><br />


</div>
</div>";
echo "<div class='clear'>";
echo "<br /><br /><hr>";
echo "</div></div>";
}
}

echo "</form>";
}
else echo "You Have No Messages In Your Outbox"
?>

对于收件箱消息,它与发件箱相同,但采用收件箱形式。

我该如何解决这个问题?

最佳答案

以下代码适用于 outbox.php,因为这就是您粘贴的内容。

首先,将复选框更改为:

<input type='checkbox' name='cb$msg_id' value='$msg_id'>

类似:

<input type='checkbox' name='outbox_ids[]' value='$msg_id'>

发件箱的 elseif 将为:

elseif ($outboxbtn)
{
$selectall = $_POST['selectall'];
if ($selectall)
{
$query = mysql_query("SELECT * FROM messages WHERE from_user='$user'");
while ($row = mysql_fetch_assoc($query))
{
mysql_query("UPDATE messages SET from_delete='1' WHERE from_user='$user'");
}

echo "All messages have been deleted.";
}
else
{
if(isset($_POST['outbox_ids']){
$outbox_msg_ids = array_map('mysql_real_escape_string', $_POST['outbox_ids']);
//all the checked msg id are now stored in $outbox_msg_ids,
//we will loop through the values and pass it to the update query
foreach($outbox_msg_ids as $msg_id){
mysql_query("UPDATE messages SET from_delete='1' WHERE to_user='$user' AND id='$msg_id'");
}
echo "The selected messages have been deleted.";
} //isset if block ends
}
}

注意:

Please, don't use mysql_* functions in new code 。它们不再维护and are officially deprecated 。请参阅red box ?了解 prepared statements相反,并使用 PDO ,或MySQLi -this article将帮助您决定哪个。如果您选择 PDO,here is a good tutorial .

关于php - 收件箱、发件箱删除错误 - 请帮助我,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22740924/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com