If I'm understanding correctly, you are getting all the information that you wish to insert into the database from the form. If this is so just do two inserts.
If its not so and the database is generating the userid you need to use for both tables, do one insert and then a select based on the insert criteria. That should give you the userid and then you can use it with the second insert. This would be in the case where the userid is an auto-incrementing index field of some sort. Though I do not think this is your problem.
Two Inserts: (All variables come from form submit or something similar)
insert into table1 (userid, name, lastname) values ('$userid', '$name', '$lastname');
insert into table2 (userid, dept,time) values('$userid', '$dept' ,'$time');
Insert, Select, Insert: (Userid is database generated)
insert into table1 (name, lastname) values ('$name', '$lastname');
select userid from table1 where name='$name' and lastname='$lastname';
$new_userid = userid from select;
insert into table2 (userid, dept,time) values('$new_userid', '$dept' ,'$time');
But just a small word of advice it would seem if you're using the same userid for both the tables that the two tables should become one. I don't know your situation but that would save a database insert and an extra table it doesn't seem that you may need.