I am doing an silly mistake in getting the location of the browser and storing using an external ip , ajax and php file.I am getting an error as
Uncaught SyntaxError: Unexpected token :
I think i am not sending the data properly in the php file, Here is my AJAX function:
$(document).ready(function() {
$.get("https://ipinfo.io", function(response) {
var city_data = val(response.city);
var region_data = val(response.region);
data: {city: city_data, region: region_data},
type: "post",
url: "test3.php",
success: function(data){
alert("Data Saved: " + data);
}
}, "jsonp");
});
and my php file as :
<?php
if(isset($_REQUEST))
{
mysql_connect("localhost","root","");
mysql_select_db("practice");
error_reporting(E_ALL && ~E_NOTICE);
print_r($_POST);
return;
$city=$_POST['city'];
$region=$_POST['region'];
$sql="INSERT INTO location(area,country) VALUES ('$city','$region')";
$result=mysql_query($sql);
if($result){
echo "Work Done.";
}
}
?>
I used mysql as this is for testing, Please have a look on my codes and let me know where i went wrong. Thanks in advance.
mysql_*is deprecated right now. Read about little bobby and SQL injection.return;saves you from SQL injections because the SQL will never get executed.If called from the global scope, then execution of the current script file is ended.