开发者

insert into 2 tables in one form

I would like make INSERT INTO to two different MySQL tables. For example,

  1. insert customer details in tblcustomer
  2. insert customer address in tbladdress

Can I make it in

$result = mysql_query(
  "INSERT INTO tblcustomer(
     txtaccount_name,txtfirst_name,txtlast_name,txtemail
     ,intoffice_no,intfax,intmobile,intother_no,dtebirth_date)
   VALUES('$acc_name','$fname','$lname','$email',
   '$office','$fax_no','$mobile_no','$others_no','$date')");

$result1 = mysql_query(
  "INSERT INTO tbladdress(
     txtmailing_add,txtothers_add,txtmailing_street,txtothers_street,
     txtmailing_city,txtothers_city,txtmailing_state,txtothers_state,
     txtmailing_postcode,txtothers_postcode,txtmailing_country,
     txtothers_country)    
  VALUES('$m_add','$o_add','$m_street','$o_street',
     '$m_city','$o_city','$m_state','$o_state',
     '$m_开发者_JAVA技巧postcode','$o_postcode','$m_country',
     '$o_country')");


Yes that would work, but you would have to execute two queries to the database, I suggest using PDO. It support transactions.


You can insert with these queries but you should make connection between customer table and customer address table if you already did not done.

They should be connected by a foreign key or something like that if the engine is not innodb.

You should escape user input using mysql_real_escape_string

or better to use PDO.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜