I am creating an android application and I am currently creating groups. Everything is fine when I insert the group into the table and echoing "success" as a JSON object.
The problem is, I need to retrieve the auto incremented id from this group. This is what my php looks like.
<?php
$con = mysqli_connect();
$gname = $_POST["gname"];
$statement = mysqli_prepare($con, "INSERT INTO groups (gname) VALUES (?)");
$id = mysql_insert_id();
mysqli_stmt_bind_param($statement, "s", $gname);
mysqli_stmt_execute($statement);
$response = array();
$response["success"] = true;
$response["id"] = $id;
echo json_encode($response);
?>
When I added the lines
$id = mysql_insert_id();
and
$response["id"] = $id;
the program stopped working. How do I retrieve the Id?