-1

Error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\webareas\ie803\projectx\search.php on line 306

My php code is as follows:

    <?php

$car = mysql_real_escape_string($_REQUEST['car']);
$model = mysql_real_escape_string($_REQUEST['model']);
$type = mysql_real_escape_string($_REQUEST['type']);
$colour = mysql_real_escape_string($_REQUEST['colour']);
$year = mysql_real_escape_string($_REQUEST['year']);
$price = mysql_real_escape_string($_REQUEST['price']);


$con = mysql_connect("--","---","---");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db('-----', $con);

$sql = "SELECT * FROM Cars WHERE Make ='$car', Model ='$model', Type ='$type', Colour = '$colour', Year  = '$year', Price = '$price'";
$result=mysql_query($sql, $con);


{
     while($info = mysql_fetch_array($result)){
        echo "<tr>";
        echo "<td>" . $info['Make']. "</td>";
        echo "<td>" . $info['Model']. "</td>";
        echo "<td>" . $info['Type']. "</td>";
        echo "<td>" . $info['Colour']. "</td>";
        echo "<td>" . $info['Year']. "</td>";
        echo "<td>" . $info['Price']. "</td>";


        echo "<br/><br/><td>" . '<hr>' .  "</td>";


}
}
echo "</tr>";
echo "</table>";
?>

line 306 is the while statement. I keep on getting errors after each change I make.

4

4 回答 4

2

select 语句只是一个字符串,您必须通过 mysql_query 将其输入以获取结果集,通常如下所示:

$sql = "SELECT * FROM Cars WHERE Make ='$car', Model ='$model', Type ='$type', Colour = '$colour', Year  = '$year', Price = '$price'";
$result=mysql_query($sql, $con);
于 2012-04-25T15:43:25.073 回答
0

你没有mysql_query(),试试

$sql = "SELECT * FROM Cars WHERE Make ='$car', Model ='$model', Type ='$type', Colour = '$colour', Year  = '$year', Price = '$price'";
$result = mysql_query($sql) or die("ERROR: ".mysql_error());

编辑 我放入 or die 语句以帮助调试,您可以随时将其删除。我个人觉得这样更容易。

于 2012-04-25T15:44:43.347 回答
0

你需要使用mysql_query之前mysql-fetch-aarray。有关如何执行此操作的示例,请参见此页面

于 2012-04-25T15:44:54.900 回答
0

我认为您的查询甚至没有被执行。我从未见过WHERE [column], [column], [column]以前的语法。

尝试:

SELECT * FROM Cars WHERE Make ='$car' AND Model ='$model' AND Type ='$type' AND Colour = '$colour' AND Year  = '$year' AND Price = '$price'

我添加了一些错误检查,如果语法正确,你可以看到你得到的任何 mysql 错误。

$sql = "SELECT * FROM Cars WHERE Make ='$car', Model ='$model', Type ='$type', Colour = '$colour', Year  = '$year', Price = '$price'";
$result=mysql_query($sql, $con);
if($result)    
{
     while($info = mysql_fetch_array($result)){
        echo "<tr>";
        echo "<td>" . $info['Make']. "</td>";
        echo "<td>" . $info['Model']. "</td>";
        echo "<td>" . $info['Type']. "</td>";
        echo "<td>" . $info['Colour']. "</td>";
        echo "<td>" . $info['Year']. "</td>";
        echo "<td>" . $info['Price']. "</td>";


        echo "<br/><br/><td>" . '<hr>' .  "</td>";


}
else {
    die(mysql_error();
}
于 2012-04-25T16:36:41.020 回答