I am trying to insert data into my table such the id field is one more than my previous max id. For example, if I had 21 users registered and another one was added, then that users' id would be 21 (note my ids start at 0). I tried this:
mysqli_query($con,"INSERT INTO logins (ID,UserName)
VALUES ((SELECT COUNT(ID) FROM logins),'$username')");
This is the error message: #1093 - You can't specify target table 'logins' for update in FROM clause
I also tried this which works:
$result=mysqli_query($con,"SELECT ID FROM logins WHERE ID=(SELECT MAX(ID) FROM logins)");
while ($db_field = mysqli_fetch_assoc($result))
{
$id=$db_field['ID']+1;
mysqli_query($con,"INSERT INTO logins (ID, UserName)
VALUES ('$id','$username'");
break;
}
But I am looking for a way to do this with one command. Thanks in advance.