我正在尝试升级我的代码以删除所选邮件。下面是我现有的代码,我想改变它,
<input type="hidden" name="action" value="delete" />
<input type="submit" name="deletebtn" value="Delete" onclick="if(!confirm('Are you sure you want to delete selected messages?')) return false;" />
$template->assign('script', 'messages');
if(isset($_POST['action']))
{
$action = makesafe($_POST['action']);
$ids = $_POST['msgid'];
if(!empty($ids))
{
if($action == 'delete')
{
foreach($ids as $k => $v)
{
if(!empty($v))
{
if(mysql_num_rows(mysql_query("SELECT * FROM messages WHERE receiver = '"logged id"' AND msg_id = '$v' LIMIT 1")))
{
if(mysql_query("DELETE FROM messages WHERE msg_id = $v AND receiver = '"logged id"' LIMIT 1"))
{
$success_msg = "Message(s) Deleted.";
}
}
}
}
}
}
}
我尝试使用此代码,但它不起作用,
<button type="submit" class="btn" name="delete" onclick="if(!confirm('Are you sure you want to delete selected links?')) return false;" > <i class="icol-cross"></i> Delete </button>
我还想验证用户是否单击了删除按钮而未选择任何消息(复选框)。
答案 0 :(得分:1)
对于您的确认按钮,您应该使用以下代码:
<button type="submit" class="btn" name="delete" onclick="return confirm('Are you sure you want to delete selected links?')" > <i class="icol-cross"></i> Delete </button>
对于SQL语句,我不确定在两个查询中使用两个引号时你期望得到什么(又名&#39;&#34;登录&#34;&#39;),I认为你应该只使用一种,或者#39;或\&#34;,因为您已经用双引号包装此查询。
祝你好运!