Jump to content

Search Help


pauldonnelly23

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.