You were very nearly there.
Try this code
PHP Code:
$host = "localhost";
$user = "manleynet";
$pass = "mypassword";
$dbname = "sitename_co_uk";
//connect to the database
$connection = mysql_connect($host, $user, $pass) or die (' Can\'t connect to the database ' . mysql_error() . '<br />');
mysql_select_db($dbname);
//connect to the database we wish to work with and find results
$sql = 'SELECT make, price'
. ' FROM cars'
. ' WHERE'
. ' make = \'' . $_POST['make'] . '\''
. ' AND'
. ' price = ' . $_POST['price']
;
echo $sql;
$result = mysql_query($sql);
if (false == $result)
{
echo 'Failed to execute ' . $sql . ' due to ' . mysql_error() . '<br />';
}
else
{
echo '<p>here is the content of this database</p>';
//Display the results of each line in a paragraph
while ($row = mysql_fetch_array($result))
{
echo '<p>' . $row['make'] . ' : ' . $row['price'] . '<br />';
}
}
In SQL statements, strings should be quoted (e.g. make) and integers not quoted (e.g. price). MySQL will allow you to quote numbers, but this is not recommended practice.
Also, you should only select those columns that you actually need. This reduces the amount of data transferred between the MySQL server and the web server and hence speeds up the query.
Hope this helps
Bookmarks