简体   繁体   中英

mysql_insert_id() is returning 0

I've looked through the various answers and none of them seem to be helping. I have a simple Insert Query that is working as expected. Nothing special

$user_account_query = mysqli_query($dbc,"
        INSERT INTO ACCOUNT (EMAIL, IS_OPEN)
        VALUES ('$email', 1)")
        or die ('Could not add user: '. mysql_error());

It is successfully inserting the record into my db

在此处输入图片说明

I also have an auto-incrementing column in the table being called 在此处输入图片说明

However, when I call

$message = mysql_insert_id();

I get 0. Does anyone have any advice on how to get the correct ID?

You're mixing up mysql and mysqli

$message = mysql_insert_id();

should be

$message = mysqli_insert_id($dbc);

实际上,您正在使用myqli Libraray,然后使用其他库函数mysql_insert_id(),则必须使用mysqli_insert_id(),这就是为什么您获得0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM