【发布时间】:2013-07-29 11:09:13
【问题描述】:
所以当我这样做时
<?php echo $_GET['id']; ?>
我得到一个结果:1
但是当我将它用于我的查询时,我得到了错误
This discussion does not exists.
我复制粘贴了一点代码,因为这个问题不需要其余的代码。 这是我的代码:
if(isset($_GET['id']))
{
$id = $_GET['id'];
//We get the title and the narators of the discussion
$req1 = $db->prepare('select title, user1, user2 from pm where id="'.$id.'" and id2="1"');
$req1->execute();
$dn1 = $req1->fetch();
echo $dn1['title'];
{
echo '<div class="message">This discussion does not exists.</div>';
}
}
【问题讨论】:
-
您可以使用 PHPMyAdmin 测试查询吗?
select title, user1, user2 from pm where id="1" and id2="1" -
你能告诉你
connection code或参考这个php.net/manual/en/mysqli-stmt.fetch.php。还要检查您的数据库中是否有数据。使用if else显示title或no record found message。 -
最后一个块运行不管,你忘了添加条件吗?
-
如果您不使用 bind() 或将参数传递给 execute() 来绑定参数,那么使用 prepare() 是没有意义的。
-
@RohanKumar 我没有使用 mysql1 :s