Search DB HELP

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

[code]

[/code]

Search.php

[code]<?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
$pubaddress
$pubtown
$pubcounty
$pubdetails
$pubweb


";
}
?>[/code]

I think the functions isset() and mysql_num_rows() will come in handy for this application.

Sponsor our Newsletter | Privacy Policy | Terms of Service