Hi all, first post here.
I have a database here containing name, zip code, and address fields. I also have a page with a field n which you would type a zip code. The idea is that if that zip code exists in the database, it would return the name, zip code, and address that are associated with that zip code. Simple, or no? A simple address look-up using only a zip code.
How to create a simple address search?
Moderator: General Moderators
-
GradyLorenzo
- Forum Newbie
- Posts: 6
- Joined: Wed Mar 09, 2011 4:40 pm
Re: How to create a simple address search?
Hint:
Code: Select all
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
if (isset($_POST['zipcode']){
$sql = "SELECT name,zip,address FROM table WHERE zip='".mysql_real_escape_string($_POST['zipcode'])."' ";
$qry = mysql_query($sql);
while($data = mysql_fetch_array($qry)){
echo "<div>".$data['name']." , ".$data['zip']." , ".$data['address']."</div>";
}
}
-
GradyLorenzo
- Forum Newbie
- Posts: 6
- Joined: Wed Mar 09, 2011 4:40 pm
Re: How to create a simple address search?
The browser complained about that bit..
-
jim.barrett
- Forum Newbie
- Posts: 20
- Joined: Tue Mar 01, 2011 5:47 am
Re: How to create a simple address search?
did you get an error message from the code that was posted by Peec? It looks like it will work, except for one typo...
you need to add another )...so
Code: Select all
if (isset($_POST['zipcode']){
Code: Select all
if (isset($_POST['zipcode'])){