php未定义变量-不确定是否与sql查询有关


php undefined variable - not sure if is to do with the sql-query

查询有什么问题?

$sql="select * from cars where make LIKE '%$term%' AND town LIKE '$town' AND colour LIKE '$colour' AND Reg LIKE '$Reg' AND price > $price AND miles > $miles LIMIT $offset";
echo "<br>";

if (isset($_session['term']))$_session['term']="%";

echo "<br>";

$term=mysql_query($sql,$odbc) or die("Can not run query");
if(mysql_num_rows($term)==0)
{
    echo "no records returned";
}
else
{
    $recCount=mysql_num_rows($term);

    echo"<table>";
        echo"<tr >";
            echo"<td width=130 valign=top> <h4>Search Return:</h4></td>"; 
            echo"<td valign=top>$recCount</td>" ; 
            echo"<td width=150 valign=top> records are found.</td>";
        echo"</tr>";
    echo"</table>";

查询应该更像:

SELECT * 
FROM cars 
WHERE make LIKE '%".$term."%' 
AND town LIKE '%".$town."%' 
AND colour LIKE '%".$colour."%' 
AND Reg LIKE '%".$Reg."%' 
AND price > ".$price." 
AND miles > ".$miles." 
LIMIT ".$offset;

尽管您可能想了解mysqli或PDO