我遇到mysql_fetch_array
的问题。我收到警告:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\wamp\www\bb.php on line 6 bool(false)
这是我的代码:
if (isset($_POST['chapter'])AND isset($_POST['verse'])){
$db=mysql_connect("localhost","fruanthony","admin");
mysql_select_db("gths",$db);
$results=mysql_query("SELECT * FROM bible where verse=".$_POST['verse']."AND chapter=".$_POST['chapter']);
while($a=mysql_fetch_array($results)){
echo $a['info'] ;
echo "<br>";
}
}
答案 0 :(得分:0)
$results=mysql_query("SELECT * FROM bible where verse='".$_POST['verse']."' AND chapter='".$_POST['chapter']."'");
您缺少查询值'".$_POST['chapter']."'"
中的单引号,请注意单引号
答案 1 :(得分:0)
替换
$results=mysql_query("SELECT * FROM bible where verse=".$_POST['verse']."AND
chapter=".$_POST['chapter']);
TO
$results=mysql_query("SELECT * FROM bible where verse = '".$_POST['verse']."' AND chapter = '".$_POST['chapter']."'");
答案 2 :(得分:0)
现在尝试:)
if (isset($_POST['chapter']) AND isset($_POST['verse'])) {
// Dont ignore SQL injection
$safeChapter = mysql_real_escape_string($_POST['chapter']);
$safeVerse = mysql_real_escape_string($_POST['verse']);
$db=mysql_connect("localhost","fruanthony","admin");
mysql_select_db("gths",$db);
$results=mysql_query("SELECT * FROM bible where verse='".$safeVerse."' AND chapter='".$safeChapter."';");
while($a=mysql_fetch_array($results))
{
echo $a['info'] ;
echo "<br>";
}
}