I am trying to direct a user to the proper location based on zip code. I have a table of valid zip codes in my database already. When a user enters a valid zip code they will fill out the form, other wise they will be redirected to another site. The problem is, that when I type any zip code that I haven't set up, I get only a blank page. Here is the code. I have left out the part where I store the users info, but it is working in both cases. If I leave out the redirection and type in an unsupported zip, I get an error, mysql_num_rows does not have valid record source result. It will not print 0 as $num. You can try this at: http://ideas4profit.com/credit/apply.htm The only 2 zip codes that work (are in the table) are 94015 and 94014.
<?
//connect to database
$connection2 = @mysql_connect("localhost", "username", "password");
$db2 = @mysql_select_db(database, $connection2);
//retreive data to see if zip is in the list
$sql2 = "SELECT * FROM table WHERE zip = '$_POST[zip]'";
$result2 = mysql_query($sql2,$connection2) or die(mysql_error());
$num = mysql_num_rows($result2);
//decide what to do with visitor
if ($num == 1) {
$msg = "<P>Please fill out all fields</P>";
} else {
header( "Location: http://www.otherwebsite.com");
exit;
}
?>
<html>
<head>
<title>Application</title>
</head>
<body>
Thank you
<?
print "$_POST[fname]";
?>
<br>
<?
print "$today";
?>
<br>
<?
print "$num";
?>
<br>
<?
print "$msg";
?>
</body>
</html>