Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $error = array();
- $nome = isset($_POST['nome']) ? trim($_POST['nome']) : '';
- if (empty($nome)) {
- $error[] = urlencode('campo nome obbligatorio');
- }
- $cognome = isset($_POST['cognome']) ? trim($_POST['cognome']) : '';
- if(empty($cognome)){
- $error[] = urlencode('campo cognome obbligatorio');
- }
- $civico = isset($_POST['civico']) ? trim($_POST['civico']) : '';
- $citta = isset($_POST['citta']) ? trim($_POST['citta']) : '';
- $prov = isset($_POST['prov']) ? trim($_POST['prov']) : '';
- if($_POST){
- // get latitude, longitude and formatted address
- $data_arr = geocode($_POST['indirizzo']);
- // if able to geocode the address
- if($data_arr){
- $lat = $data_arr[0];
- $lon = $data_arr[1];
- $formatted_address = $data_arr[2];
- $lat = isset($_POST['lat']) ? trim($_POST['lat']) : '';
- $lon = isset($_POST['lon']) ? trim($_POST['lon']) : '';
- }else{
- echo "you are back to full circle again";
- }
- function geocode($indirizzo){
- $indirizzo = isset($_POST['indirizzo']) ? urlencode($indirizzo) : '';
- $url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address={$indirizzo}";
- $resp_json = file_get_contents($url);
- $resp = json_decode($resp_json, true); if($resp['status']='OK'){
- $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;
- $stmt = $dbh->prepare("UPDATE tagesroma SET nome=?, cognome=?, indirizzo=?, civico=?, citta=?, prov=?, lat=?, lon=? WHERE id=?"); // changed to WHERE id=?
- $stmt->execute(array($nome, $cognome, $indirizzo, $civico, $citta, $prov, $lati, $longi, $_GET["id"])); // added $_GET["id"] to the end
- }else{
- return false;
- }
- }else{
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement