Advertisement
Guest User

Untitled

a guest
Sep 25th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. $error = array();
  2. $nome = isset($_POST['nome']) ? trim($_POST['nome']) : '';
  3. if (empty($nome)) {
  4. $error[] = urlencode('campo nome obbligatorio');
  5. }
  6. $cognome = isset($_POST['cognome']) ? trim($_POST['cognome']) : '';
  7. if(empty($cognome)){
  8. $error[] = urlencode('campo cognome obbligatorio');
  9. }
  10.  
  11. $civico = isset($_POST['civico']) ? trim($_POST['civico']) : '';
  12.  
  13. $citta = isset($_POST['citta']) ? trim($_POST['citta']) : '';
  14.  
  15. $prov = isset($_POST['prov']) ? trim($_POST['prov']) : '';
  16.  
  17. if($_POST){
  18.  
  19. // get latitude, longitude and formatted address
  20. $data_arr = geocode($_POST['indirizzo']);
  21.  
  22. // if able to geocode the address
  23. if($data_arr){
  24.  
  25. $lat = $data_arr[0];
  26. $lon = $data_arr[1];
  27. $formatted_address = $data_arr[2];
  28.  
  29. $lat = isset($_POST['lat']) ? trim($_POST['lat']) : '';
  30.  
  31. $lon = isset($_POST['lon']) ? trim($_POST['lon']) : '';
  32.  
  33. }else{
  34. echo "you are back to full circle again";
  35. }
  36.  
  37. function geocode($indirizzo){
  38.  
  39. $indirizzo = isset($_POST['indirizzo']) ? urlencode($indirizzo) : '';
  40.  
  41. $url = "http://maps.google.com/maps/api/geocode/json?sensor=false&address={$indirizzo}";
  42.  
  43. $resp_json = file_get_contents($url);
  44.  
  45. $resp = json_decode($resp_json, true); if($resp['status']='OK'){
  46. $lati = $resp['results'][0]['geometry']['location']['lat'];
  47. $longi = $resp['results'][0]['geometry']['location']['lng'];
  48. $formatted_address = $resp['results'][0]['formatted_address'];
  49. // verify if data is complete
  50. if($lati && $longi && $formatted_address){
  51.  
  52. // put the data in the array
  53. $data_arr = array();
  54.  
  55. array_push(
  56. $data_arr,
  57. $lati,
  58. $longi,
  59. $formatted_address
  60. );
  61.  
  62. return $data_arr;
  63.  
  64. $stmt = $dbh->prepare("UPDATE tagesroma SET nome=?, cognome=?, indirizzo=?, civico=?, citta=?, prov=?, lat=?, lon=? WHERE id=?"); // changed to WHERE id=?
  65. $stmt->execute(array($nome, $cognome, $indirizzo, $civico, $citta, $prov, $lati, $longi, $_GET["id"])); // added $_GET["id"] to the end
  66.  
  67. }else{
  68. return false;
  69. }
  70. }else{
  71. return false;
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement