我正在尝试建立一个简单的注释系统,我想在注释和登录页面之间创建相关性。。。。那么当用户到达blog.php时呢?id=3,他们将得到正确的评论。
我正在做的是创建一个带有pageid列的注释表。当用户向页面发帖时,将填充pageid列。也许是隐藏的表单字段?如何在我的MYSQLI 中进行这种关联
这就是我的想法。。。
<?php
include_once("includes/check_login_status.php");
?>
<?php
// Check to see the URL variable is set and that it exists in the database
if (isset($_GET['id'])) {
// Connect to the MySQL database
include "includes/db_conx.php";
$id = preg_replace('#[^0-9]#i', '', $_GET['id']); // filter everything but numbers
// Use this var to check to see if this ID exists, if yes then get the product
// details, if no then exit this script and give message why
$sql = "UPDATE content SET views=views+1 WHERE ID=$id";
$update = mysqli_query($db_conx,$sql);
$sql = "SELECT * FROM content WHERE id=$id LIMIT 1";
$result = mysqli_query($db_conx,$sql);
$productCount = mysqli_num_rows($result);
if ($productCount > 0) {
// get all the product details
while($row = mysqli_fetch_array($result)){
$article_title = $row["article_title"];
$category = $row["category"];
$readmore = $row["readmore"];
$author = $row["author"];
$date_added = $row["date_added"];
$article_content = $row["content"];
}
} else {
echo "That item does not exist.";
exit();
}
} else {
echo "Data to render this page is missing.";
exit();
}
?>
<?php
include_once "includes/db_conx.php";
$sql = "SELECT * FROM comment WHERE pageid ="$id"ORDER BY id DESC";
$sql_comments = mysqli_query($db_conx,$sql);
while($row = mysqli_fetch_array($sql_comments)){
$name = $row["name"];
$comment = $row["comment"];
$commentlist .= 'name : '.$name.'<br />comment : '.$comment.'<hr>';
}
//////////////
?>
下半部分是否在get变量的范围内?这样我就可以确定我们在哪一页?这种类型的变量可以通过注释形式的变量传递吗?
第三条sql语句包含一个错误:
$sql = "SELECT * FROM comment WHERE pageid ="$id"ORDER BY id DESC";
至
$sql = "SELECT * FROM comment WHERE pageid =".$id."ORDER BY id DESC";
您可能还想将pre_replace语句更改为intval:
$id = preg_replace('#[^0-9]#i', '', $_GET['id']);
至
$id = intval($_GET['id']);
原因是如果$_GET['id']='ABC123',那么preg_replace将返回123,而intval将返回0。