I'm a beginner in PHP. I have a problem in a form, i have to verify if the user is sending me an adress of Paris or not.
<?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é";
}
?>
So I added this line
if($longitude > 48.7 and $longitude < 49 and $latitude > 2.2 and $latitude < 2.5){
Because when the user post the adress I have a script which come out the latitude and longitude into hidden input. So I tried to check if he is inside Paris or not with this line. Because if the adress is not in Paris, I don't want to send the datas.
Today my form send it anyway, so i guess i have an error in this line. But i couldn't find it.
And here is my script
<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>