a2bardeals Posted September 12, 2006 Share Posted September 12, 2006 i am having some trouble searching my database. the db is set up like an address book. name, address, city, state, phone, id(int) *auto_increment* i created the db then created a php script to populate the db with entries. now i want to search those entries. i tried going this route but it returns a blank page.of course i have a form page (search.html) that the action is set to srch.phpsrch.php:<font face="arial, helvetica" size="1"><? $username = "XXXXXX"; $password = "XXXXXXX"; $database = "aXXXXXXXX"; $server = "localhost"; @mysql_connect($server,$username,$password); @mysql_select_db($database);?><?$result = mysql_query("SELECT name, city, state, id FROM a2_bars WHERE name LIKE '".$_POST['term']."'");if (!$result) {echo 'Could not run query: ' . mysql_error();exit;}while ($row = mysql_fetch_array($result, MYSQL_NUM)) { printf('%s<br>%s<br><br>', $row[0], $row[1]);}mysql_free_result($result);?> Quote Link to comment Share on other sites More sharing options...
fenway Posted September 12, 2006 Share Posted September 12, 2006 A blank page? That must be a PHP problem. Quote Link to comment Share on other sites More sharing options...
jstu327 Posted September 13, 2006 Share Posted September 13, 2006 Hi a2bardeals,Here are a few things I would check. 1. Make sure the method in search.html is set to POST because that is what you are using in your query.2. If that is set to POST, then you can look at your query. Try putting an actual name in that you know exists in your database.i.e. $result = mysql_query("SELECT name, city, state, id FROM a2_bars WHERE name LIKE 'Bob' "); (or whatever name might exist)3. If that gives you a result, then the problem lies with your WHERE name LIKE '".$_POST['term']."'Try setting a variable to your search term and using it in your query accordingly.i.e.$searchcontact = $_POST ['term'];$result = mysql_query("SELECT name, city, state, id FROM a2_bars WHERE name LIKE '%$searchcontact%' ");Also, I've found it helpful to put some html on the result page, or print out "ran successfully" after my queries during testing. That way, if the page comes up but there are no results, then you have query problems. But, if the page is blank it's most likely a syntax error in your php somewhere. In that case, just check your error logs. Hope this helps you out!Jay Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.