kelseyirene Posted December 10, 2009 Share Posted December 10, 2009 I've been struggling with this all afternoon. The code seems correct, no problems are turning up, I'm connecting to the database, but the search isn't yielding results that I know are there. My table is fairly simple, it's basically a list of the books I own... my columns are 'num' 'title' 'author_first' 'author_last' 'isbn' and 'read'. Ideally, I'd like to be able to search for any keyword in any of the columns, but for now I just want to figure out how to do the search form. Here's the code I used for the form: <form method="post" action="search.php"> <div align="center"> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td bordercolor="#000000"> <p align="center"> <select name="num" size="1"> <option value="title">Title</option> <option value="telephone">Author Last</option> <option value="birthday">ISBN</option> </select> <input type="text" name="search" size="25"> <br> Search database: <input type="submit"></p> </td> </tr> </table> </div> </form> -- and this is the form I used for search.php: <center> <table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000"> <tr> <td width="60"><b>num</b></td> <td width="100"><b>title</b></td> <td width="70"><b>author last</b></td> <td width="150"><b>isbn</b></td> </tr> <tr> <td> <? $con = mysql_connect("localhost","username","password") or die(mysql_error()); mysql_select_db("my_db",$con); ?> <? //error message (not found message)begins $XX = "No Record Found, to search again please close this window"; //query details table begins $query = mysql_query("SELECT * FROM TitleInfo WHERE $num LIKE '%$search%' LIMIT 0, 50"); while ($row = @mysql_fetch_array($query)) { $variable1=$row["num"]; $variable2=$row["title"]; $variable3=$row["author_last"]; $variable4=$row["isbn"]; //table layout for results print ("<tr>"); print ("<td>$variable1</td>"); print ("<td>$variable2</td>"); print ("<td>$variable3</td>"); print ("<td>$variable4</td>"); print ("</tr>"); } //below this is the function for no record!! if (!$variable1) { print ("$XX"); } //end ?> </table> </center> </html> -- help!! what am I doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/184693-help-trying-to-create-php-search-form-and-its-not-working/ Share on other sites More sharing options...
harkly Posted December 11, 2009 Share Posted December 11, 2009 It doesn't look like you are passing anything to the search form. You have this LIKE '%$search%' but where is the $search, you need to define it. Quote Link to comment https://forums.phpfreaks.com/topic/184693-help-trying-to-create-php-search-form-and-its-not-working/#findComment-975163 Share on other sites More sharing options...
cags Posted December 11, 2009 Share Posted December 11, 2009 As harkly says you don't manually assign a value to $search. Since your form has an input that has a name attribute of 'search' it would seem you are relying on register_globals being enabled, which it may not be. Quote Link to comment https://forums.phpfreaks.com/topic/184693-help-trying-to-create-php-search-form-and-its-not-working/#findComment-975343 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.