I have this in index.php I would like to get my input data (range) as variable into my nova.php. When I am trying to use $range = $_GET['range']; in nova.php it shows : Undefined index: range. I think, I should put something like data:{range: range} into myAjax function. But of course it's not working
<input id="range" type="text" name="range" class="enter" value="">
<input type="button" onclick="myAjax()" value="Show nearby" />
my ajax
function myAjax() {
$.ajax({
type: "POST",
url: 'nova.php',
data:{action:'call_this'},
success:function(html) {
alert(html);
}
});
}
and my nova.php:
<?php
if($_POST['action'] == 'call_this') {
$con=mysqli_connect("localhost","tech","151987","portnew");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$range = $_GET['range'];
// Perform queries
$query = $con->query("SELECT ( 6371 * acos( cos( radians(53.216908) )*
cos( radians( lat ) ) * cos( radians( lng ) - radians(7.453240) ) +
sin( radians(53.216908) ) * sin( radians( lat ) ) ) ) AS distance,
port_name FROM ports HAVING distance < '".$range."' ORDER BY distance LIMIT 0 , 20; ");
while ($row = $query->fetch_assoc()) {
$port_list[] = $row['port_name'];
}
echo json_encode($port_list);
}
?>
So basically this script is looking for nearby locations based on latitude, logitude. It's working when I put ...HAVING distance < 150 ORDER BY...
, but I would like to set my range in input, and not using static range