Jump to content

[SOLVED] Is mysql_insert_id the best way to keep the same id?


poleposters

Recommended Posts

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());

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.