if mysql select returns no results redirect
Posted: Wed Dec 15, 2010 7:55 pm
First time using a DB(MYSQL) and php to produce a little search.
I have a list of zip codes for sales reps. The intial search worked great, but I want to have an if/else so if someone enters a zip code that is not in my database they are taken to a different page or recieve a message.
Not haveing much luck.
Here is the code I have and need the code help for if the zip is not in the database... beable to post text or link to a page:
I have a list of zip codes for sales reps. The intial search worked great, but I want to have an if/else so if someone enters a zip code that is not in my database they are taken to a different page or recieve a message.
Not haveing much luck.
Here is the code I have and need the code help for if the zip is not in the database... beable to post text or link to a page:
Code: Select all
<?php
mysql_connect ("localhost", "peterson_galiant","p3t3rs0n") or die (mysql_error());
mysql_select_db ("peterson_zipcode");
$term = $_POST['term'];
$sql = mysql_query("select * from reps_zip where zip like '%$term%'");
while ($row = mysql_fetch_array($sql)){
echo '<img src="'.$row['picture'].'" width=274>';
echo '<br/>'.$row['name'];
echo '<br/> <a href="'.$row['page'].'">Contact Info</a>';
echo '<br/><br/>';
}
?>