J'ai encore besoin de votre aide :
j'ai une variable $commune qui arrive d'un formulaire avec le nom d'une commune mais précédé par un espace
le probleme je voudrais virer cette espace avant l'insertion dans le BDD avec une variables qui pourrait s'appeler $commune2
si vous avait une petite solution ,je vous en remercie par avance.
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{
font-family:arial;
font-size:.8em;
}
input[type=text]{
padding:0.5em;
width:20em;
}
input[type=submit]{
padding:0.4em;
}
#gmap_canvas{
width:100%;
height:30em;
}
#map-label,
#address-examples{
margin:1em 0;
}
</style>
</head>
<body>
<center>
<?php
if($_POST){
$rue= $_POST['address'];
$commune =$_POST['commune'];
$address= $_POST['address'].$_POST['commune'];
$name = $_POST['name'];
$type = $_POST['type'];
// get latitude, longitude and formatted address
$data_arr = geocode($_POST['address']." ".$_POST['commune']);
// if able to geocode the address
if($data_arr){
$latitude = $data_arr[0];
$longitude = $data_arr[1];
$formatted_address = $data_arr[2];
try
{
$bdd = new PDO('mysql:host=myhost;dbname=mydbdname;charset=utf8', 'bdd, 'mypassworld', $pdo_options);
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
echo "<center><h2>Creation d'un nouveau POI 2/2</h2></center>";
echo "<center><h3>voici les information saisie :</h3></center>";
echo "<center><h4>Nom du Poi : $name</h4></center>";
echo "<center><h4> Type POI : $type </h4> <h4> adresse : $address</h4></center>";
echo "<center><h4>Commune : $commune </h4>";
echo "<center><h4>Longitude : $longitude et Latitude : $latitude</h4></center>";
$req = $bdd->prepare('INSERT INTO prevision(id, name, address, lat, lng, type, commune, date, url_lieu, img, categorie) VALUES("", :name, :rue, :lat, :lng, :type, :commune, CURDATE(), "nc.pdf", "nc.jpg", "4")');
$req->execute(array(
'name' => $name,
'rue' => $rue,
'lat' => $latitude,
'lng' => $longitude,
'type' => $type,
'commune' => $commune,
'lng' => $longitude,
'type' => $type,
'commune' => $commune,
));
if($req)
{
echo "<center>Statut BDD: Le POI à bien été ajouté dans la base de Données</center>";
}
else
{
echo "<center>Statut BDD: Erreur d'insertion dans la Base de Données, Veuillez réessayer, si le problème persiste veuillez contacter l'Administrateur du site.</center>";
}
?>
<?php
?>
<?php
// if unable to geocode the address
}else{
echo "adresse non trouver.";
}
}
?>
<?php
// function to geocode address, it will return false if unable to geocode address
function geocode($address){
// url encode the address
$address = urlencode($address);
// google map geocode api url
$url = "http://maps.google.com/maps/api/geocode/json?address={$address}";
// get the json response
$resp_json = file_get_contents($url);
// decode the json
$resp = json_decode($resp_json, true);
// response status will be 'OK', if able to geocode given address
if($resp['status']=='OK'){
// get the important data
$lati = $resp['results'][0]['geometry']['location']['lat'];
$longi = $resp['results'][0]['geometry']['location']['lng'];
$formatted_address = $resp['results'][0]['formatted_address'];
// verify if data is complete
if($lati && $longi && $formatted_address){
// put the data in the array
$data_arr = array();
array_push(
$data_arr,
$lati,
$longi,
$formatted_address
);
return $data_arr;
}else{
return false;
}
}else{
return false;
}
}
?>