runeveryday Posted November 2, 2010 Share Posted November 2, 2010 this is the creation table code.the database is testing. CREATE TABLE users (fname VARCHAR(30), lname VARCHAR(30), info BLOB); INSERT INTO users VALUES ( "Jim", "Jones", "In his spare time Jim enjoys biking, eating pizza, and classical music" ), ( "Peggy", "Smith", "Peggy is a water sports enthusiast who also enjoys making soap and selling cheese" ),( "Maggie", "Martin", "Maggie loves to cook itallian food including spagetti and pizza" ),( "Tex", "Moncom", "Tex is the owner and operator of The Pizza Palace, a local hang out joint" ) the html code: <h2>Search</h2> <form name="search" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Seach for: <input type="text" name="find" /> in <Select NAME="field"> <Option VALUE="fname">First Name</option> <Option VALUE="lname">Last Name</option> <Option VALUE="info">Profile</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> the search code: <?php if ($searching =="yes") { echo "<h2>Results</h2><p>"; if ($find == "") { echo "<p>You forgot to enter a search term"; exit; } mysql_connect("localhost", "root", "123") or die(mysql_error()); mysql_select_db("database_name") or die(mysql_error()); $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); $data = mysql_query("SELECT * FROM users WHERE upper($field) LIKE'%$find%'"); while($result = mysql_fetch_array( $data )) { echo $result['fname']; echo " "; echo $result['lname']; echo "<br>"; echo $result['info']; echo "<br>"; echo "<br>"; } $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Sorry, but we can not find an entry to match your query<br><br>"; } echo "<b>Searched For:</b> " .$find; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/217539-why-the-code-cant-search/ Share on other sites More sharing options...
trq Posted November 2, 2010 Share Posted November 2, 2010 Where is $field defined? Quote Link to comment https://forums.phpfreaks.com/topic/217539-why-the-code-cant-search/#findComment-1129386 Share on other sites More sharing options...
runeveryday Posted November 2, 2010 Author Share Posted November 2, 2010 i don't know, it's from here, how to correct the code? Quote Link to comment https://forums.phpfreaks.com/topic/217539-why-the-code-cant-search/#findComment-1129462 Share on other sites More sharing options...
runeveryday Posted November 3, 2010 Author Share Posted November 3, 2010 it's an examploe form here . http://php.about.com/od/phpwithmysql/ss/php_search_3.htm there are something wrong with this search code.but i don't know how to correct it. Quote Link to comment https://forums.phpfreaks.com/topic/217539-why-the-code-cant-search/#findComment-1129729 Share on other sites More sharing options...
Airzooka Posted November 3, 2010 Share Posted November 3, 2010 If that is everything you have in your search script ("code"), $field and $find have no values. You'll need to add this to the beginning of the script: $field = $_POST['field']; $find = $_POST['find']; If that isn't what's wrong, tell us what doesn't work. Does the query fail, or are no results returned? Quote Link to comment https://forums.phpfreaks.com/topic/217539-why-the-code-cant-search/#findComment-1129733 Share on other sites More sharing options...
jcbones Posted November 3, 2010 Share Posted November 3, 2010 Also add: $searching = $_POST['searching']; Quote Link to comment https://forums.phpfreaks.com/topic/217539-why-the-code-cant-search/#findComment-1129757 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.