【问题标题】:Doesn't see any data in my post [closed]在我的帖子中没有看到任何数据[关闭]
【发布时间】:2011-12-14 10:55:10
【问题描述】:

我在 index.php 页面中没有看到任何数据。我使用此代码从具有唯一 ID 的 mysql 数据库中获取数据,但我不能。

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&nbsp;&nbsp;" . "<b>Category:</b>    
&nbsp;$cat_name". "&nbsp;&nbsp;".  "<b>by:</b>&nbsp;&nbsp;" . "$poster&nbsp;&nbsp;" . 
"<b>Comemnts</b>[&nbsp;  ]" ;
}
?>

【问题讨论】:

  • 您发布的代码无效。请尝试发布工作代码。
  • 这是我的 index.php 代码。 dawamedical.com/index.txt
  • 这段代码的输入错误似乎太多
  • 您也是打字新手吗?只有你需要的只是仔细粘贴你正在使用的实际代码。
  • 你确定数据库连接正常吗?

标签: php mysql


【解决方案1】:

前两行代码在打开标记之前:

【讨论】:

  • 你的脚本工作了吗?
【解决方案2】:

你有一个变量$p_id

但是在查询中你使用 $pid 变量名。

【讨论】:

  • 哦,我改变了这个,但仍然一无所获
【解决方案3】:
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");
}

【讨论】:

  • 第 102 行显示未定义变量:C:\xampp\htdocs\evantechbd\index2.php 中的 p_id
  • 好吧,你在某处使用了这样一个未定义的变量。检查有关此变量的代码
  • 当然,去检查你的实际代码。你至少在地址栏中用 post_id 调用你的 index.php 吗?
  • 这是我的index.php的代码,请看这个..dawamedical.com/index.txt
  • 你用地址栏中的 post_id 调用你的 index.php 吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多