3

我似乎找不到这个。也许我问错了问题。我的数据库中的第一个字段是 INT 设置为自动递增的 id。当我创建一个新条目时,我想获取创建的 id,但我不知道如何。

$query = mysqli_query($myConnection, "INSERT INTO books (title, author, description) 

VALUES('$title','$author','$description')") 

or die (mysqli_error($myConnection));



echo 'Operation Completed Successfully! <br /><br /><a href="index.php">Click Here</a><br /><br />';


//HERE I WOULD ALSO LIKE TO ECHO THE ID THAT WAS CREATE WITH AUTO INCREMENT
echo $title . "<br />" . $author . "<br /> . $description;
4

2 回答 2

7

尝试这个:

echo "The last id was: " . msqli_last_insert_id();
于 2013-09-26T16:29:42.913 回答
3

使用这个功能:mysqli_insert_id()

于 2013-09-26T16:30:29.973 回答