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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.