Mega Code Archive

 
Categories / Php / Searching
 

Search Your Database

//This is the form I use to initiate the script (call this find.php) <form method=post action="search.php"> Search For: <p> User Name: <input type=text name=user size=25 maxlength=25> <p> Password: <input type=text name=passwd size=25 maxlength=25> <p> <input type=submit> </form> //search.php <? //You should now this but be sure to connect to your database or this is useless. :/ if ($user == "") {$user = '%';} if ($passwd == "") {$passwd = '%';} // $user and $passwd are the two column names I used. Change this to fit your database $result = mysql_query ("SELECT * FROM yourtable WHERE user LIKE '%$user%' AND passwd LIKE '%$passwd%' "); if ($row = mysql_fetch_array($result)) { do { PRINT "<b>User Name: </b> "; print $row["user"]; print (" "); print ("<br>"); PRINT "<b>Passwd: </b> "; print $row["passwd"]; print ("<p>"); PRINT "<b>FirstName: </b> "; print $row["firstname"]; print ("<p>"); } while($row = mysql_fetch_array($result)); } else {print "Sorry, no records were found!";} //The end result prints the username / passwd / firstname / lastname / ID / email //you will have to change these fields also to fit your needs ?>