humbleiam humbleiam - 4 months ago 17
SQL Question

How will I get mysqli last insert id

How will i get the last insert id in mysql following code?

All variable are set.

Insertion works!

$Restconnection = mysqli_connect("host","user","passwd","db ");
$query3 = mysqli_query($Rconnection, $strSQL3);

Answer
$sql = "INSERT INTO Table_name VALUES(?,?,?)";
if ($Restconnection->query($sql) === TRUE) {
    $last_id = $conn->insert_id;
    echo "Last inserted ID is: " . $last_id;
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}