In this SQL query construct you execute it no matter what is the value of txtSearchField
(even if it is empty). You also forgot to put the dollar sign $ on front of this variable txtSearchField
, that's why you cannot get any results from your input form, because you always search for text txtSearchField
, not the content of the variable $txtSearchField
. (I guess you use an input form with HTML text input which is called txtSearchField
). Remember to set your HTML form's method to "post", because if you omit it, the default is "get".
If I`m right, you should rework your code in this way:
<?php
//Sanitize user input
$txtSearchField = filter_var($_POST['txtSearchField'], FILTER_SANITIZE_STRING);
//SQL query
$query = "SELECT property.propertyid, property.propertyname
FROM property
WHERE CONCAT(property.address_1, ' ',
property.address_2, ' ',
property.postcode, ' ',
property.area) LIKE '%$txtSearchField%'" //see the $ sign here
//Finally, execute query and get result
$result = mysql_query ($query) or die ('SQL error occured: '.mysql_error());
while ($array = mysql_fetch_assoc($result)) {
echo $result['address_1'].'/'.$result['address_2'].'/'.$result['postcode'].'/'.$result['area'].'<br/>';
}
?>