I have an if statement for retrieving the lat and long from an address and insert it into a sql database. I have the basic structure of the form working but wish to include empty field checking and pregmatch but if i try an enter more else if statements the nothing happens.
// Your Google Maps API key
$key = "key";
// Desired address
$address = 'http://maps.google.com/maps/geo?q='.$location.'&output=json&oe=utf8&sensor=false&key=$key';
// Retrieve the URL contents
$data = file_get_contents($address);
// Parse the returned XML file
$jsondata = json_decode($data,true);
if (is_array($jsondata )&& $jsondata ['Status']['code']==200){
$lat = $jsondata ['Placemark'][0]['Point']['coordinates'][0];
$lon = $jsondata ['Placemark'][0]['Point']['coordinates'][1];
}
elseif (mysql_query("INSERT INTO database (type, category, suggest, title, url, description, phone, fax, facebookpage, twitterpage, busemail, number, streetAddress, city, state, zip, country, name, email, latitude, longitude)
VALUES ('$type', '$category', '$title', '$url', '$description', '$phone', '$fax', '$facebookpage', '$twitterpage', '$busemail', '$number', '$streetAddress', '$city', '$state', '$zip', '$country', '$name', '$email', '$lat', '$lon')"); {
die( header ("Location: http://www.exampleerrorpage.com" ) . mysql_error());
}
else { mail( $email, "Subject", $message, $headers );
header( "Location: http://www.examplecomplete.com/" );
}
Thanks in advance for any help.
Edit only have basic knowledge in php and am still very much a newbie. Be Gentle. Thanks again.
EDIT – The address portion of the form my not always be there. So the geocode does not always need to execute.
Just slowly go through your logic again and think. Your programs says:
You simply have a very screwed up if-then-else logic.
Logic-wise, you probably want something along the lines of: