I made an HTML form that contains two text fields: one for the "name" and the other for the "phone".
The user enters data in both fields and my PHP script searches for the colomn that matches both fields (name and phone). I use the following command:
$result = mysql_query("SELECT * FROM applicants WHERE name='$name' AND phone='$phone");
The problem is that I want if the user leaves the "phone" filed empty, then the PHP code searches using the "name" only and ignore the "phone". If the user enters the phone only, then the search ignores the name and only uses the phone for search. If the user leaves both fields empty, then the search returns all the rows in the database table. I want a method that can work easily if the number of files is more than 2 (ex: name, phone, country, ... etc.)
2007-03-06
20:08:42
·
2 answers
·
asked by
shafaki
2