Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6879937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:54:37+00:00 2026-05-27T04:54:37+00:00

I have an if statement for retrieving the lat and long from an address

  • 0

I have an if statement for retrieving the lat and long from an address and insert it into a sql database. I have the basic structure of the form working but wish to include empty field checking and pregmatch but if i try an enter more else if statements the nothing happens.

// Your Google Maps API key
$key = "key";
// Desired address
$address = 'http://maps.google.com/maps/geo?q='.$location.'&output=json&oe=utf8&sensor=false&key=$key';
// Retrieve the URL contents
$data = file_get_contents($address);
// Parse the returned XML file
$jsondata = json_decode($data,true); 
if (is_array($jsondata )&& $jsondata ['Status']['code']==200){ 
  $lat = $jsondata ['Placemark'][0]['Point']['coordinates'][0]; 
  $lon = $jsondata ['Placemark'][0]['Point']['coordinates'][1];
}
elseif (mysql_query("INSERT INTO database (type, category, suggest, title, url, description, phone, fax, facebookpage, twitterpage, busemail, number, streetAddress, city, state, zip, country, name, email, latitude, longitude) 
VALUES ('$type', '$category', '$title', '$url', '$description', '$phone', '$fax', '$facebookpage', '$twitterpage', '$busemail', '$number', '$streetAddress', '$city', '$state', '$zip', '$country', '$name', '$email', '$lat', '$lon')");     {
die( header ("Location: http://www.exampleerrorpage.com" ) . mysql_error());
}
else { mail( $email, "Subject", $message, $headers );
header( "Location: http://www.examplecomplete.com/" );
}

Thanks in advance for any help.

Edit only have basic knowledge in php and am still very much a newbie. Be Gentle. Thanks again.

EDIT – The address portion of the form my not always be there. So the geocode does not always need to execute.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:54:38+00:00Added an answer on May 27, 2026 at 4:54 am

    Just slowly go through your logic again and think. Your programs says:

    If the JSON data is valid, set the two variables $lat and $lon,
    else (if the JSON data is not valid but) if the SQL query returns true, die with an error,
    else (if none of the above), send an email.

    You simply have a very screwed up if-then-else logic.

    Logic-wise, you probably want something along the lines of:

    if (/* JSON data not valid */) {
        die('Error');
    }
    
    $lat = ...;
    $lon = ...;
    
    // Prevent SQL injection!
    $lat = mysql_real_escape_string($lat);
    $lon = mysql_real_escape_string($lon);
    
    $query = "INSERT INTO ...";
    if (!mysql_query($query)) {
        die(mysql_error());
    }
    
    if (!mail(...)) {
        die('Error sending mail');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have sql statement like this SELECT DISTINCT results_sp_08.material_number FROM results_sp_08 INNER JOIN courses
I have sql statement one; select linkscat.id, linkscat.category from linkscat, contentlinks, links where contentlinks.linksid
I have LINQ statement that looks like this: return ( from c in customers
I have following statement for query articles from some sections Article.all(:joins => :sections, :conditions
If I have a list of ID's that I have selected from a statement
i have found an very good method for retrieving any result set from the
I have a statement level trigger that fires whenever INSERT UPDATE or DELETE operations
I'm having trouble retrieving data from my database using Spring Jdbc. Here's my issue:
I have strange effects when retrieving columns of type DATE from SQLServer2008 using the
Are there any free solutions for automatically migrating a database from MySQL to SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.