PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Ok first if I have posted in wrong section sorry.... Hi new to php and looking for some general help with code I am writing for a project I have to do and I have ran into some problems with the code and have been getting errors.. and well dont know were to turn so looking for any help to point out the fault in my code. Here is the code I have written....errors are happening on line 24 and if I change the the code I then get error on line 33 at the echo any help please.
<?php
$dbconnection = mysql_connect("","","");
if (!$dbconnection)
{
die('Unable to connect … ' . mysql_error());
}
mysql_select_db("car_dealer", $dbconnection);
/*//This is the original code*/
/*//$query = mysql_query("SELECT * FROM cars where make = 'ford'");
$query = mysql_query("SELECT * FROM cars where make LIKE '".$_POST['frmmake']."' AND price <=".$_POST['frmprice']." AND enginesize >= ".$_POST['frmenginesize']." AND transmision ='".$_POST[frmtransmission]."' AND fuel ='". $_POST['frmfuel']."'"); */
//$query = mysql_query("SELECT * FROM cars where make = 'ford'");
$query = mysql_query("SELECT * FROM cars where make LIKE '".$_POST['frmmake']."' AND price <=".$_POST['frmprice']."'AND engine_capacity >=".$_POST['frmengine_capacity'].AND "transmission ='".$_POST[frmtransmission]."'AND fuel ='".$_POST['frmfuel']."'");
//$query = mysql_query("SELECT * FROM cars");
echo $query;
while($row = mysql_fetch_array($query))
{
//echo $row['make']. " " .$row['model'] . "£" . $row['price'];
echo "<br />";
}
mysql_close($dbconnection);
?>
passthebuck - $query is assigned to a resource returned by mysql_query - its not the SQL statement itself.
Are you sure your SQL statement is valid ? Change line 24 to and see if any error occurs.
$sql = "SELECT * FROM cars where make LIKE '".$_POST['frmmake']."' AND price <=".$_POST['frmprice']."'AND engine_capacity >=".$_POST['frmengine_capacity'].AND "transmission ='".$_POST[frmtransmission]."'AND fuel ='".$_POST['frmfuel']."'";
$query = mysql_query($sql) or die(mysql_error()."<hr>".$sql);
$query = mysql_query("SELECT * FROM cars where make LIKE '".$_POST['frmmake']."' AND price <= '".$_POST['frmprice']."' AND engine_capacity >='".$_POST['frmengine_capacity']."'AND transmission ='".$_POST[frmtransmission]."'AND fuel ='".$_POST['frmfuel']."'");
incidentally, it would be a good idea to make sure that the $_POST variables contain what you expect. Also, using mysql_real_escape_string() before you put data into an sql query is good.