这个问题我之前问过,也没有很好的解释。我有一个脚本可以处理表单上的地址,对其进行地理编码并将其插入数据库。地理编码有效,mysql 查询无效,邮件功能无效。我已经包含了 captca 函数代码、地理编码代码、插入语句和邮件函数。我还将添加 pregmatch 和 "empty" 来检查空字段。
验证码和地理编码都有效,但插入和邮件无效。
问题 - else 语句在地理编码后不起作用。
注意 - 并不总是需要地理编码功能。这取决于表格的该部分是否已填写。有人确实提到地理编码总是返回“true”,是否可以根据输入的地址进行更改?
// 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" );
}
如果有人可以请进行调整,将不胜感激。提前致谢。