I suspect @Gil has the right answer. Using the mysql function last_insert_id() is a more straightforward approach however:
mysql> create temporary table users (id int unsigned not null auto_increment primary key, email text, password text, firstname text, lastname text); Query OK, 0 rows affected (0.00 sec) mysql> insert into users (id,email,password,firstname,lastname) values ('','[email protected]', 'password','dan','f'); ERROR 1366 (HY000): Incorrect integer value: '' for column 'id' at row 1
This depends on whether you're in strict mode (thanks to comment below )
mysql> insert into users (id,email,password,firstname,lastname) values (null,'[email protected]', 'password','dan','f'); Query OK, 1 row affected (0.00 sec) mysql> create table qualification (q_id int unsigned not null); Query OK, 0 rows affected (0.02 sec) mysql> insert into qualification( q_id) values (last_insert_id() ); Query OK, 1 row affected (0.00 sec) mysql> select * from users,qualification; +----+--------------+----------+-----------+----------+------+ | id | email | password | firstname | lastname | q_id | +----+--------------+----------+-----------+----------+------+ | 1 | [email protected] | password | dan | f | 1 | +----+--------------+----------+-----------+----------+------+ 1 row in set (0.00 sec)
idof''into theuserstable; that makes no sense to me. Edit: obviously it is, or else theechowouldn't show right. But why it would work I still don't know ( see below);or die(mysql_error())give you a error message?auto_incrementforid, an empty string''ornullwill both just cause it to use the next auto-inc as normal. (personally I prefer to leave it out of the list though)q_idan integer? if so, change('$userid')to($userid)mysql_*functions in new code. They are no longer maintained and are officially deprecated. Learn about prepared statements instead, and use PDO or MySQLi.