selecting * from mysql database
Posted: Sat Jun 11, 2005 12:30 pm
I'm very new to PHP & databases and am trying to write a script that displays information about the local businesses in my MySQL database, based on information from a form about the nature/name of business and the location (village). It all works fine in a search for businesses of a specified name/type in a specified village, but I really want to offer the option of searching for a specified name/type of business in the whole area (G63). 'G63' is one of the options in the form. I'm getting no error messages, but no results are being returned. Please help, I've hit a brick wall!
The PHP is as follows:
Many thanks in advance.
The PHP is as follows:
Code: Select all
<?php
$businesstype= ($_POST['businesstype']);
$village= ($_POST['village']);
if ($village == 'G63') {//This is the bit I'm getting stuck at!
$query= "SELECT * FROM business_directory WHERE Name LIKE '%businesstype%' OR Type LIKE '%businesstype%'";
$result= mysql_query($query)
or die ("couldn't execute query");
}
else{
$query= "SELECT * FROM business_directory WHERE Village = '$village' AND (Name LIKE '%$businesstype%' OR Type LIKE '%$businesstype%')";
}
$result= mysql_query($query)
or die ("couldn't execute query");
?>