First of all, I apologize for my "newbieness" in advance. I've got a form processing script that is working fine except for one section of code, snippets of which is shown below:
//default values
$formResponse = "How are you really doing? Use this to find out!";
$imgSource = "blue.png";
If ($country == "United States") {
//US zip code query
$sql = "SELECT location, revParData FROM zipData WHERE zipCode = '$zipCode' LIMIT 1";
mysql_select_db('db');
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
$formResponse = "It looks like you entered an invalid zip code. Please try again!";
$imgSource = "yellow.png";
} else {
$sql = "SELECT location, revParData FROM zipData WHERE zipCode = '$zipCode' LIMIT 1";
mysql_select_db('db');
$retval = mysql_query( $sql, $conn );
while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
$location = $row['location'];
$revParData = $row['revParData'];
}
}
What I thought would happen is this:
If the zip code entered by the end user does not exist in the table, the $formResponse and $imgSource values would be the "... invalid zip code" and "yellow.png" values. If a valid zip code is entered, it completes the second query.
In fact, it works fine if a zip code that exists in the table is entered, but shows the default values for $formResponse and $imgSource if a zip code that doesn't exist in the database is entered.
I can't figure out why it is doing this... if anyone can point out my coding error, it would be appreciated.
Cheers!
Mike