小编Mum*_*mbo的帖子

为什么mysqli_insert_id()总是返回0?

我有以下代码.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)

php mysql

14
推荐指数
2
解决办法
3万
查看次数

标签 统计

mysql ×1

php ×1