मेरे पास निम्न कोड है। Mysqli_insert_id() (इस मामले में "$ last_row"), जो तालिका की आखिरी पंक्ति वापस करने वाला है, हमेशा 0 लौटा रहा है। ऐसा क्यों है?mysqli_insert_id() हमेशा 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);
}
?>
"* वापसी मान: AUTO_INCREMENT फ़ील्ड का मान जिसे पिछली क्वेरी द्वारा अपडेट किया गया था। ** यदि कनेक्शन पर कोई पिछली क्वेरी नहीं थी या क्वेरी ने AUTO_INCREMENT मान ** अपडेट नहीं किया था, तो शून्य लौटाता है। * " – DCoder
देखें: http://php.net/manual/en /mysqli.insert-id.php –