<?php
$value = json_decode(file_get_contents('php://input'));
$mysql_pekare= new mysqli ("serv", "user","pass", "db");
if(!empty($value)) {
$stmt = $mysql_pekare->prepare("INSERT INTO users (`username`, `password`) VALUES(?,?)");
$stmt->bind_param("ss", $value->username, $value->password);
$stmt->execute();
if(!empty($stmt)) {
$contacts = array();
$id = mysqli_insert_id();
$contact = array("objectId" => ($id));
array_push($contacts, $contact);
echo json_encode(array('results' => $contacts), JSON_PRETTY_PRINT);
}
$stmt->close();
$mysql_pekare->close();
}
?>
Now when I insert my info from my frontend the value (username + password) gets added into MySQL just fine with a unique ID but I do not get the returned ID, currently I get it like this:
{
"results": [
{
"objectId": null
}
]
}