Im using javascript ajax to post a value to PHP.
In this case, its an object of {x: 5, y, 5}
This will create a proper sql query which results in INSERT.
if (isset($_POST["item"])) {
$var = $_POST["item"];
$x = $var["x"];
$y = $var["y"];
$sql = "INSERT INTO hex (id, x, y) VALUES (NULL, $x, $y)";
}
This however, will not work - at all. Why and how can it be fixed ? - thanks
if (isset($_POST["item"])) {
$var = $_POST["item"];
$sql = "INSERT INTO hex (id, x, y) VALUES (NULL, $var["x"], $var["y"])";
}
Will not work either:
if (isset($_POST["item"])) {
$var = $_POST["item"];
$sql = "INSERT INTO hex (id, x, y) VALUES (NULL, '$var["x"]', '$var["y"]')";
}