First off, this question has been asked before but my code style is a bit different than those in the previous questions.
I have MSSQL server and I use PHP to insert into my database.
This works.
I just need to get the last inserted ID after it has been inserted.
So this is my code:
$email=str_replace("'","''", $_POST['email']);
$password=str_replace("'","''", $_POST['password']);
$query="INSERT INTO Profiles(";
$query=$query."VP_Email,";
$query=$query."VP_Password";
$query=$query.") VALUES (?,?) SELECT SCOPE_IDENTITY() AS ins_id";
$stmt = sqlsrv_prepare($conn, $query, array(&$email, &$password));
$result = sqlsrv_execute($stmt);
if (!$result) {
echo "error: Insert Error";
exit;
} else {
sqlsrv_next_result($stmt);
sqlsrv_fetch($stmt);
$Profileid = sqlsrv_get_field($stmt,0);
}
echo $Profileid;
When i run my code, the data gets inserted into the database but the $Profileid
is always empty!
Could someone please advice on this issue?
Thanks in advance.