NasimUddinAhmmad Posted January 13, 2015 Share Posted January 13, 2015 (edited) Hello friends, I am a novice in php. Though I create 2 scripts: 1. students registration form 2. search students by Registration Number Our students' Registration Numbers are as follows: nifeA001, nifeA002 & so on... But when someone enter just "nife" or "n" or "A" etc all the students's data is showing. I want that students can search data by entering only Full Registration Number not a Part. I am placing the search.php code below. Please help me out.... ----------------- Search.php ------------------ <?php mysql_connect("localhost", "root", "") or die("could not connect"); mysql_select_db("student") or die("could not connect"); //collect if(isset($_POST['search'])) { $searchq = $_POST['search']; $searchq = preg_replace("#[^0-9a-z]#i", "", $searchq); //here $query = mysql_query("SELECT * FROM user WHERE registration LIKE '%$searchq%'") or die("could not search!"); $count = mysql_num_rows($query); if($count == 0){ $output = 'There was no search results!'; }else{ while($row = mysql_fetch_array($query)) { $fname = $row['firstname']; $lname = $row['surname']; $id = $row['registration']; $output .= '<div> '.$id.' '.$fname.' '.$lname.'</div>'; } } } ?> <html> <head> </head> <body> <form action="form.php" method="post"> <input type="text" name="search" placeholder="search for students.." <input type="submit" value=">>" /> </form> <?php print("$output");?> </body> </html> Edited January 13, 2015 by NasimUddinAhmmad Quote Link to comment https://forums.phpfreaks.com/topic/293892-php-search-mysql/ Share on other sites More sharing options...
Solution Barand Posted January 13, 2015 Solution Share Posted January 13, 2015 Use "=" instead of "LIKE" WHERE registration = '$searchq' Quote Link to comment https://forums.phpfreaks.com/topic/293892-php-search-mysql/#findComment-1502789 Share on other sites More sharing options...
NasimUddinAhmmad Posted January 13, 2015 Author Share Posted January 13, 2015 @Guru Thanks for Help Quote Link to comment https://forums.phpfreaks.com/topic/293892-php-search-mysql/#findComment-1502813 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.