php - INSERT INTO logins (ID) VALUES ((SELECT COUNT(ID) FROM logins)) Not Working -
i trying insert data table such id field 1 more previous max id. example, if had 21 users registered , 1 added, users' id 21 (note ids start @ 0). tried this:
mysqli_query($con,"insert logins (id,username) values ((select count(id) logins),'$username')");
this error message: #1093 - can't specify target table 'logins' update in clause
i tried works:
$result=mysqli_query($con,"select id logins id=(select max(id) logins)"); while ($db_field = mysqli_fetch_assoc($result)) { $id=$db_field['id']+1; mysqli_query($con,"insert logins (id, username) values ('$id','$username'"); break; }
but looking way 1 command. in advance.
i suggest make id
primary key of table , enable auto_increment. can remove id
column query, , increasing id's added automatically.
Comments
Post a Comment