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 ('','dan@site.com', '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,'dan@site.com', '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 | dan@site.com | password | dan | f | 1 |
+----+--------------+----------+-----------+----------+------+
1 row in set (0.00 sec)