简体   繁体   中英

PHP Geocode and Insert

I have asked this question before and did not explain it very well. I have a script that processess an address on a form, geocodes it and insert it into a database. The geocoding works, the mysql query does not work, and the mail function does not work. I have included the captca function code, the geocoding code, the insert statement and the mail function. I am also going to add pregmatch and "empty" to check for empty fields.

Both the captcha code and the geocode work but the insert and the mail do not.

The problem - The else statements do not function after the geocode.

Note - the geocode function will not always be required. It depends if that section of the form was filled in. Someone did mention that the geocode always return "true" can it be changed depending if an address has been entered?

// Security code handling start
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
echo "The security code entered was incorrect.<br /><br />";
echo "Please go <a href='javascript:history.go(-1)'>back</a> and try again.";
exit;
}
// Security code handling finish
// 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 (pricing, type, category, suggest, title, url, description, phone, fax, facebookpage, twitterpage, busemail, number, streetAddress, city, state, zip, country, name, email, latitude, longitude) 
VALUES ('$pricing', '$type', '$category', '$suggest', '$title', '$url', '$description', '$phone', '$fax', '$facebookpage', '$twitterpage', '$busemail', '$number', '$streetAddress', '$city', '$state', '$zip', '$country', '$name', '$email', '$lat', '$lon')");
}
else {mail( $email, "Your Submission", $message, $headers );
header( "Location: http://www.completepage.com" );
    }

If anyone can please make the adjustments it will be much appreciated. Thanks in advance.

There is syntax error after elseif. Please check the syntax...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM