我有以下代码.mysqli_insert_id()(在本例中为"$ last_row"),应该返回表的最后一行,总是返回0.为什么会这样?
<?php
include('connect-db.php');
$submit_date = date("Ymd");
$content = mysqli_real_escape_string($connection, htmlspecialchars($_POST['editor']));
$ip_address = $_SERVER['REMOTE_ADDR'];
$last_row = mysqli_insert_id($connection);
if ($content != '') {
$sql = "INSERT INTO source ( track_id, submit_date, ip, content) VALUES ('$last_row', '$submit_date','$ip_address','$content')";
if (!mysqli_query($connection,$sql))
{
die('Error: ' . mysqli_error($connection));
}
echo $last_row;
mysqli_close($connection);
}
?>
Run Code Online (Sandbox Code Playgroud)