我是PHP的初学者。 我在表单中遇到问题,我必须验证用户是否向我发送了巴黎的地址。检查表格上的用户的经度和纬度
<?php
$msg="";
$db = mysqli_connect("localhost", "root", "", "dbname");
if (isset($_FILES["image"]) AND !empty($_FILES['image']['name']))
{
$tailleMax = 3097152;
$extensionsValides = array('jpg', 'jpeg', 'png');
if($_FILES['image']['size'] <= $tailleMax)
{
$extensionUpload = strtolower(substr(strrchr($_FILES['image']['name'], '.'), 1));
if(in_array($extensionUpload, $extensionsValides))
{
$newName = uniqid(mt_rand(1, 5));
$imageName = $newName.".".$extensionUpload;
$chemin = "images/".$imageName;
$resultat = move_uploaded_file($_FILES['image']['tmp_name'],$chemin);
}else{
$msg = "Le format doit être jpg, jpeg ou png";
}
}else{
$msg = "Photo trop grande";
}
}
if (isset($_POST['upload'])) {
$image = $_FILES["image"]["name"];
$about = $_POST["about"];
$name = $_POST["name"];
$adress = $_POST["adress"];
$category = $_POST["category"];
$latitude = $_POST["lat"];
$longitude = $_POST["lng"];
if($longitude > 48.7 and $longitude < 49 and $latitude > 2.2 and $latitude < 2.5){
$sql = "INSERT INTO paristable
(picture, name, about, adress, category, latitude, longitude)
VALUES ('$imageName', '$name', '$about', '$adress', '$category', '$latitude', '$longitude')";
mysqli_query($db, $sql);
$msg = "Envoi réussi";
}else{
$smg= "Veuillez rentrer une adresse parisienne";
}
}else{
$msg= "L'envoi a échoué";
}
?>
所以我加入这行
if($longitude > 48.7 and $longitude < 49 and $latitude > 2.2 and $latitude < 2.5){
,因为当用户发布ADRESS我有一个脚本出来的纬度和经度隐入输入。所以我试图检查他是否在巴黎或者不在这条线上。因为如果地址不在巴黎,我不想发送数据。
今天我的表单发送它,所以我想我有这条线的错误。但我找不到它。
这里是我的脚本
<script>
function showAlert(){
var getLocation = function (address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({
'address': address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
console.log(latitude, longitude);
document.getElementById('lat').value = latitude;
console.log(latitude);
document.getElementById('lng').value = longitude;
console.log(longitude);
}
});
};
document.getElementById('location').value = getLocation(document.getElementById('adress').value);
console.log(document.getElementById('location').value);
document.getElementById('lat').value = latitude;
document.getElementById('lng').value = longitude;
console.log(document.getElementById('lat').value);
}
</script>
尝试使用&&代替,并在条件 – trommelaap
你的脚本是[SQL注入攻击]的风险(http://stackoverflow.com/questions/60174/如何防止SQL注入在PHP) 看看发生了什么[小Bobby表](http://bobby-tables.com/)甚至 [如果你是逃避投入,它不安全!](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string) 使用[准备好的参数化语句](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) – RiggsFolly
所以你问用户输入他们的latlongs然后你信任他们与他们输入? –