r00tk1LL Posted July 17, 2007 Share Posted July 17, 2007 I have a search form that has 5 fields, 1 drop-down box, & 1 set of radio buttons. I would like users to be able to submit any combination of fields and have only the filled in fields queried in the DB (MySQL). Problem one: How do I have the php file I'm posting to see that a field is empty, and then query only what has been submitted? Problem two: How do I use a wildcard function I.E. "LIKE" with these queries? Here is some code $username = "UN"; $password = "PW"; $hostname = "HN"; $db = "DB"; $link = mysql_connect ( $hostname, $username, $password); //user input variables $name=$_POST['name']; $age=$_POST['age']; $location=$_POST['location']; $marital=$_POST['marital']; $hobbies=$_POST['hobbies']; $interests=$_POST['interests']; $sex = $_POST['sex']; //start SQL connect if (! $link){ die ("<center><h1>Couldn't connect to MySql Server</h1></center>"); } mysql_select_db ($db) or die ("Couldnt find the database"); //process the query //following line is the problem. Dont know how to use LIKE. Dont know if I should use || or && $query="SELECT field1, field2, field3 FROM mypages WHERE sex='$sex' && marital='$test' "; //would have more variables $result=mysql_query($query); mysql_close($link); I appreciate any help you can give me, here is the url if interested. http://www.mynorthtexas.com/mypages/final/ Link to comment https://forums.phpfreaks.com/topic/60445-phpmysql-search-w-blank-fields/ Share on other sites More sharing options...
lieme Posted January 28, 2010 Share Posted January 28, 2010 hey, i'm kinda new here i was just wondering if you got you code working. i am having the same problem and i dont know how to fix it. i would appreciate it if you can share the solution with me.. tnx. Link to comment https://forums.phpfreaks.com/topic/60445-phpmysql-search-w-blank-fields/#findComment-1002911 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.