我在index.php页面中没有看到任何数据。我用这段代码从mysql数据库中获取具有唯一id的数据,但我不能。
include "db/db.php";
$upload_path = "secure/content/blogpostimg";
<?php
if (isset($_GET['post_id']) && $_GET['post_id'] != '')
{
$p_id = (int) $_GET['post_id'];
}
$sql = mysql_query("SELECT * FROM blog_post WHERE post_id = '$pid' ORDER BY post_id
DESC ");
while ($rel = mysql_fetch_assoc($sql))
{
$id = $rel['post_id'];
$sub = $rel['subject'];
$imgname = $rel['img_name'];
$msg = $rel['message'];
$date = $rel['date'];
$poster = $rel['poster'];
$cat_name = $rel['cat_name'];
echo "<h1>". "$sub" ."</h1>". "<br/>";
echo '<img src="' . $upload_path . '/' . $imgname . '" width="200" /> ';
include_once("func.php");
echo truncate($rel['message'],"index.php","post_id",$rel['post_id']);
echo "$date " . "<b>Category:</b>
$cat_name". " ". "<b>by:</b> " . "$poster " .
"<b>Comemnts</b>[ ]" ;
}
?>
答案 0 :(得分:3)
前两行代码在open标记之前: &LT; PHP
答案 1 :(得分:0)
error_reporting(E_ALL);
ini_set('display_errors',1);
在代码的最顶部添加这两行,并阅读问题的答案 这将让你发现你开始的那些愚蠢的错别字。
现在,让我们对SQL做同样的事情
使你的代码像这样
if (isset($_GET['post_id']))
{
$p_id = (int) $_GET['post_id'];
}
else
{
die('Required variable is not set');
}
$sql = "SELECT * FROM blog_post WHERE post_id = $p_id";
$res = mysql_query($sql) or trigger_error(mysql_error()." ".$sql);
if (!mysql_num_rows($res))
{
die("No records found");
}
答案 2 :(得分:0)
您有一个变量 $ p_id
但在查询中,您使用 $ pid 变量名。