Sunday, 26 March 2017

how to make a search form with multiple search options in php

Suppose These are fields:-

$user_name = $_POST[‘user_name’]$city = $_POST[‘city’]

Take a variable:-

$sql = ‘SELECT * FROM USER_TABLE WHERE 1=1’;

(i)   Now if user fills something in user_name:-

If(!empty($user_name))Then :-$sql = $sql . ‘AND user_name = ’.$user_name;

(ii) Now if user fills something in city:-

If(!empty($city))Then :-$sql = $sql . ‘AND city = ’.$city;And then run this query :- mysql_query($sql) 

No comments :

Post a Comment