pauldonnelly23 Posted March 4, 2008 Share Posted March 4, 2008 Hi, I've created this script which will allow me to search mySQL database via PHP. My only problem is I dont know how to create php in my script to display "Sorry, No Records Found" and if the form is left blank an error msg to appear. Can Anyone Help Me? Many Thanks, Paul Entry.php <form method="post" action="search.php"> <input type="text" name="search" size=25 maxlength=25> <input type="Submit" name="Submit" value="Submit"> </form> Search.php <?php mysql_connect("localhost","user","password"); mysql_select_db("majorproject"); $search=$_POST["search"]; $result = mysql_query("SELECT * FROM pubdirectory " . "WHERE pubname LIKE '%".$search."%'". " OR pubcounty LIKE '%".$search."%'" . " ORDER BY pubcounty"); while($r=mysql_fetch_array($result)) { $pubname=$r["pubname"]; $pubaddress=$r["pubaddress"]; $pubtown=$r["pubtown"]; $pubcounty=$r["pubcounty"]; $pubdetails=$r["pubdetails"]; $pubweb=$r["pubweb"]; $pubdir_id=$r["pubdir_id"]; echo "$pubname <br> $pubaddress <br> $pubtown <br> $pubcounty <br> $pubdetails <br> $pubweb <br><hr>"; } ?> Link to comment https://forums.phpfreaks.com/topic/94288-search-help/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.