【发布时间】:2015-07-28 20:02:06
【问题描述】:
我正在尝试从数据库中检索数据并打印它们。这是我的代码
$sql="SELECT * FROM table1 WHERE c_no='".mysql_real_escape_string($_SESSION['user']['c'])."'.AND a_no='".mysql_real_escape_string($_SESSION['user']['a'])."'";
$result=mysql_query($sql,$connect);
echo "<table>";
$num_of_rows=mysql_num_rows($result);
echo $num_of_rows;
for($k=0;$k<3;$k=$k+2){
echo "<th>";
echo mysql_field_name($result,$k);
echo "</th>";
}
while($r=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$r["field1"]."</td><td>".$r["field2"]."</td>";
echo "</tr>";
}
此代码给出错误mysql_num_rows(): supplied argument is not a valid MySQL result resourcemysql_fetch_assoc(): supplied argument is not a valid MySQL result resourcemysql_field_name(): supplied argument is not a valid MySQL result resource
这是为什么?我的会话变量工作正常,就像我使用时一样echo $_SESSION['user']['a'];它工作正常吗?是 WHERE 子句的问题吗?
【问题讨论】:
标签: php sql session where-clause