0
I have a bank problem. When registering a user the ID is set to 0. I try to use Auto Increment, but when I activate this option, the other entries stop working.
0
I have a bank problem. When registering a user the ID is set to 0. I try to use Auto Increment, but when I activate this option, the other entries stop working.
0
If I understand correctly, you want to PHP
, so you can do it this way.
First make a SELECT
of all users before inserting, use a 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 find the last inserted. If it does not exist, just a small condition that you insert with id = 1
, that is, see the code summarized.
$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)");
}
Browser other questions tagged php phpmyadmin
You are not signed in. Login or sign up in order to post.
No code, no help.
– Mateus
Which you can’t? In phpmyadmin or in php code?
– I_like_trains
It is common in these cases to create a function that retrieves the last ID and adds + 1
– Alexandre Cavaloti