I have a bank problem. When registering a user the ID is given as 0. I try to use Auto Increment, but when I activate this option, the other registers stop working.
I have a bank problem. When registering a user the ID is given as 0. I try to use Auto Increment, but when I activate this option, the other registers stop working.
If I understand correctly, you want to PHP
, so you can do it this way.
First make a SELECT
of all users before entering, use code similar to this
$este=mysqli_query($variavel_db, "SELECT * FROM tabela order by id DESC LIMIT 0, 1");
With the above code you will get the last inserted. If it does not exist, a small condition that suffices to enter with id = 1
, that is, see the summarized code.
$este=mysqli_query($variavel_db, "SELECT * FROM tabela order by id DESC LIMIT 0, 1");
if(mysqli_num_rows($este) == 0){
$insert=mysqli_query($variavel_db, "INSERT INTO tabela (id, valor1, valor2, etc) VALUES (1, valor1, valor2, etc)");
}else{
$mos=mysqli_fetch_assoc($este);
$plus=$mos['id']+1;
$insert=mysqli_query($variavel_db, "INSERT INTO tabela (id, valor1, valor2, etc) VALUES ('$plus', 'valor1', 'valor2', etc)");
}