mysql insert/select question

admin

Administrator
Staff member
Hi,

I'm inserting a row into a MYSQL table that already exsists. I'm wondering if it's possible to return the unique id of the new row with one statement. For example instead of saying:

"INSERT INTO table (first_name, last_name) values ('$name[0]', '$name[1]')";

"SELECT id FROM table WHERE first_name='$name[0]' AND last_name='$name[1]'";

Can I do this in one statement? From what I know of MYSQL, you can't but I'm worried that my select statement could return more than one id assuming that a professor could have the same first and last name although it's unlikely. All the other fields in my table are not unique except the id, so there could be a potential error. How does one make this error proof?

Thanks in advance,
-Samantha
 
Back
Top