【发布时间】:2014-01-09 12:41:00
【问题描述】:
我想允许我的用户通过链接从数据库中删除他们自己的 cmets。但是我遇到的问题是我的评论没有删除,也没有收到任何错误消息。
这是我“salonpage.php”中“deletepost.php”页面的链接:
if ($row['userID'] == $_SESSION['userID']){
$str_comments .=" <p><a href='deletepost.php?pID=".$row['ID']."&salonid=$salonid'>Delete comment</a>";
这是我的“deletepost.php”页面中的代码:
<?php
require_once("checklog.php");
require_once("nifunctions.php");
$postID = trim($_GET['pID']);
if ($postID != '' && is_numeric($postID))
{
if (!$db_server)
{
die("unable to connect to database: ".mysqli_connect_error($db_server));
}
else
{
$_GET['salonid'] and ($_GET['salonid'] != '');
$salonid = clean_string($db_server, $_GET['salonid']);
mysqli_select_db($db_server, $db_database) or die ("couldnt find database");
//Delete post from comments
$query= "DELETE FROM comments WHERE ID=$postID";
mysqli_query($db_server,$query) or
die("comment delete failed" . mysqli_error($db_server));
//redirect back to index page
header("Location: salonpage.php?salonid=$salonid");
}
//db close
mysqli_close($db_server);
}
?>
【问题讨论】:
-
您遇到的错误是什么?
-
如果您没有收到任何错误,请尝试包含以下代码行:ini_set('display_errors', 1); error_reporting(E_ALL & ~E_NOTICE);
-
我认为它在这条线上打破了:
$_GET['salonid'] and ($_GET['salonid'] != '');。那应该是什么? -
我有一个“Déjà Vue”
-
你可以通过 echo $query 进行调试;看看你得到了什么。
标签: php mysqli comments sql-delete