-3

我有问题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>";  
  }  
}
4

3 回答 3

0
$results=mysql_query("SELECT * FROM bible where verse='".$_POST['verse']."' AND            chapter='".$_POST['chapter']."'");

您在查询值中缺少单引号'".$_POST['chapter']."'"请注意单引号

于 2013-02-07T10:02:07.863 回答
0

代替

$results=mysql_query("SELECT * FROM bible where verse=".$_POST['verse']."AND chapter=".$_POST['chapter']);

$results=mysql_query("SELECT * FROM bible where verse = '".$_POST['verse']."' AND chapter = '".$_POST['chapter']."'");
于 2013-02-07T10:02:14.610 回答
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>";  
    }  
}
于 2013-02-07T10:13:15.487 回答