Hi,
I am getting undefined array key ‘home_id’ and ‘road_id’ in village.php. Seems like ajax is not passing the data to village.php file. How do I pass the data?
index.php
$("#add-to-area").on("click", function() {
var home = <?= $home_id; ?>;
var road = <?= $road_id; ?>;
$.ajax({
url: "../../area/town/village.php",
data: {home_id: home, road_id: road},
type: "POST",
success: function(response) {
//
}
})
})
village.php
include("../all/conn.php");
$home_id = $_POST["home_id"];
$road_id = $_POST["road_id"];
$sql = "INSERT INTO township (home_id, road_id) VALUES ('{$home_id}', '{$road_id}')";
if(mysqli_query($conn, $sql))
{
echo 1;
}
else
{
echo 0;
}