我已经使用以下新错误编写了此帖子
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\webareas\ie803\projectx\search.php on line 306
我的php代码如下:
<?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>";
?>
第306行是while语句。我每次改变后都会继续犯错误。
非常感谢
答案 0 :(得分: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);
答案 1 :(得分: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());
我希望有帮助
修改强> 我输入或者使用die语句来帮助调试,你可以随时删除它。我个人觉得它更容易。
答案 2 :(得分:0)
您需要在mysql_query
之前使用mysql-fetch-aarray
。请参阅此page,了解如何执行此操作
答案 3 :(得分: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();
}