Php MYSQL代码没有拉取信息

Php MYSQL代码没有拉取信息,php,mysql,html,Php,Mysql,Html,我正在写我的社交网络,当一篇文章显示在新闻提要上时,个人资料图片和作者姓名将不会显示。这是我的密码: $owner_id=mysql_result($result,$i,"post_owner_id"); //Post writer's user ID $content=mysql_result($result,$i,"content"); //Content of the post $date=mysql_result($result,$i,"date"); //Date $time=mysq

我正在写我的社交网络,当一篇文章显示在新闻提要上时,个人资料图片和作者姓名将不会显示。这是我的密码:

$owner_id=mysql_result($result,$i,"post_owner_id"); //Post writer's user ID
$content=mysql_result($result,$i,"content"); //Content of the post
$date=mysql_result($result,$i,"date"); //Date
$time=mysql_result($result,$i,"time"); //Time
$poi_query=mysql_query("SELECT firstname, lastname, profile_picture FROM users WHERE id = '" . $owner_id . "'"); //MYSQL query to get the information of the post writer using user ID
$post_firstname=mysql_result($poi_query, 0, "firstname"); //Writer's first name
$post_lastname=mysql_result($poi_query, 0, "lastname"); //Writer's Last name
$post_profile_picture=mysql_result($poi_query, 0, "profile_picture"); //Writer's profile picture
?>

      <div class="post">
        <h1 class="post-title"><a href="profile.php?user=<?php echo $owner_id; ?>"> <?php echo $post_firstname; ?> <?php echo $post_lastname; ?></a></h1>
        <p class="content"><?php echo $content; ?></p>
        <p class="details"><?php echo $date; ?> at <?php echo $time; ?></p>
        <br/><hr/><br/>
      </div>
$owner\u id=mysql\u result($result,$i,“post\u owner\u id”)//作者的用户ID
$content=mysql_result($result,$i,“content”)//文章内容
$date=mysql_result($result,$i,“date”)//日期
$time=mysql_result($result,$i,“time”)//时间
$poi_query=mysql_query(“从id='“$owner_id.”的用户中选择firstname、lastname、profile_picture”//MYSQL查询,使用用户ID获取撰稿人信息
$post_firstname=mysql_结果($poi_查询,0,“firstname”)//作者姓名
$post_lastname=mysql_结果($poi_查询,0,“lastname”)//作者姓氏
$post_profile_picture=mysql_结果($poi_查询,0,“profile_picture”)//作者简介图片
?>




除了名字和图片,其他一切都很好。有什么帮助吗?我几乎可以肯定这与poi_查询有关。。。 顺便说一下,如果我手动输入用户ID,所有代码在终端中都可以正常工作

Config.inc:

<?php

$hostname = 'localhost';        // Your MySQL hostname. Usualy named as 'localhost', so you're NOT necessary to change this even this script has already online on the internet.
 $dbname   = 'social-network'; // Your database name.
 $username = 'root';             // Your database username.
 $password = '********';                 // Your database password. If your database has no password, leave it empty.

// Let's connect to host
 mysql_connect($hostname, $username, $password) or DIE('Connection to host is failed, perhaps the service is down!');
 // Select the database
 mysql_select_db($dbname) or DIE('Database name is not available!');

?>

我能看到的唯一一件事是,是否可以删除所有者id中的引号

$poi_query=mysql_query("SELECT firstname, lastname, profile_picture FROM users WHERE id = " . $owner_id);
更改此行:

$poi\u query=mysql\u query(“从id='“$owner\u id.”的用户中选择firstname、lastname、profile\u picture;”

致:

$poi\u query=mysql\u query(“从id=”“$owner\u id.”的用户中选择firstname、lastname、profile\u picture”)或die(mysql\u error())

查看是否从MySQL收到有关查询的错误消息

编辑:

这里的问题最终是一个调用
mysql_close()干扰了
$poi_查询
分配。

尝试

$poi_query=mysql_query("SELECT firstname, lastname, profile_picture FROM users WHERE id = " . $owner_id) or die(mysql_error());
或者尝试转储变量,看看它给出了什么

var_dump($poi_query);

这将帮助您缩小问题范围

您是否尝试回显$owner_id,以确保它不会出现空白?@CassieCarter这也是一个好主意,要确保将
$owner\u id
输入到查询语句时,它是您所期望的。请在原始PHP脚本中包含此config.inc文件的位置张贴该行。