kuau
05-01-2010, 04:07 PM
I have a table of 43k zipcodes and I want to let users who are entering client addresses into a form enter the zipcode and have the city & state automatically fill in.
I tried this code but nothing shows up in the City State field...
<?php include_once('db-connectdb.php'); $sql = "SELECT citystate FROM zipcode WHERE zip = '".$_POST['zip']."'";
$result = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
$row = mysql_fetch_row($result); $citystate = $row['citystate']; ?>
<p><label>City, State:</label><input type="text" name="citystate" size="40" value="<?php echo $citystate;?>"> Zip: <input type="text" name="zip" size="15"></p>
If they have already typed in a city, I'm not sure if it should replace what they typed either. Can anyone see what I am doing wrong? Thanks!
I tried this code but nothing shows up in the City State field...
<?php include_once('db-connectdb.php'); $sql = "SELECT citystate FROM zipcode WHERE zip = '".$_POST['zip']."'";
$result = mysql_query($sql,$connection) or die("Couldn't execute $sql query. <br> mysql error: ".mysql_error());
$row = mysql_fetch_row($result); $citystate = $row['citystate']; ?>
<p><label>City, State:</label><input type="text" name="citystate" size="40" value="<?php echo $citystate;?>"> Zip: <input type="text" name="zip" size="15"></p>
If they have already typed in a city, I'm not sure if it should replace what they typed either. Can anyone see what I am doing wrong? Thanks!