poleposters Posted April 11, 2008 Share Posted April 11, 2008 I have a registration script. The user enters all sorts of information and it gets inserted into two tables. Ones with the login info and the other with the user address info. I'm running two queries and using the mysql_insert_id function to make sure that the user id stays the same in each table. I'm just curious as to whether this is the best way to do this. Is it possible that it could fail? Heres the code,it works.Just wondering if this is the best way. // Add the user. $query = "INSERT INTO users (business_id, email, pass,business, business_type, first_name, last_name, active,paid_listing, registration_date) VALUES ('','$e', SHA('$p'),'$bn', '$cat','$fn', '$ln', '$a',0, NOW() )"; $result = mysql_query ($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); $bid=mysql_insert_id(); $query2 = "INSERT INTO address (address_id,business_id,unit_number,street_number, address, postcode) VALUES ('','$bid','$bn','$un','$sn' '$ad','$pc')"; $result2 = mysql_query ($query2) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); Link to comment https://forums.phpfreaks.com/topic/100622-solved-is-mysql_insert_id-the-best-way-to-keep-the-same-id/ Share on other sites More sharing options...
MiCR0 Posted April 11, 2008 Share Posted April 11, 2008 Should be fine Link to comment https://forums.phpfreaks.com/topic/100622-solved-is-mysql_insert_id-the-best-way-to-keep-the-same-id/#findComment-514607 Share on other sites More sharing options...
haku Posted April 11, 2008 Share Posted April 11, 2008 No worries, that will work fine (at least the mysql_insert_id() part will - I didn't really look at the rest of your code). Link to comment https://forums.phpfreaks.com/topic/100622-solved-is-mysql_insert_id-the-best-way-to-keep-the-same-id/#findComment-514625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.