Search code examples
phpmysqlauto-increment

PHP + SQLi - Auto incrementing ID's


I've come across a problem where in my PHP, for some reason I have to define what the ID is or I get my "die" message, even though the table structure is set to auto increment, here is my PHP:

$query = mysqli_query($link, "INSERT INTO users (username, email, passhash, reg_ip, reg_date, salt)VALUES('$username','$email','$pass1','$ip_address',now(),'$salt')") or die("Could not create your account, please try again later.");

ID is currently not in that code, and it isn't working, if I were to do:

$id = 1;

and then add it to the insert, it works, for some reason I can't set it as NULL either.

Structure: bigint, unsigned, auto-increment, primary key.


Solution

  • Reset the auto-increment value back to 1, as you've hit the limit.

    ALTER TABLE users AUTO_INCREMENT = 1 ;