双插入MYSQLI的问题

时间:2013-08-07 01:41:07

标签: insert mysqli

您是否可以使用mysqli执行此类操作?我什么都没进。

// Place the transaction into the database   
   $sql = "INSERT INTO transactions (product_id_array, email, first_name, last_name, payment_date, mc_gross, payment_currency, txn_id, receiver_email, payment_type, payment_status, txn_type, payer_status, address_street, address_city, address_state, address_zip, address_country, address_status, notify_version, verify_sign, payer_id, mc_currency, mc_fee, ip, username)       
       VALUES('$custom','$payer_email','$first_name','$last_name','$payment_date','$mc_gross','$payment_currency','$txn_id','$receiver_email','$payment_type','$payment_status','$txn_type','$payer_status','$address_street','$address_city','$address_state','$address_zip','$address_country','$address_status','$notify_version','$verify_sign','$payer_id','$mc_currency','$mc_fee','$ip','$user_name')";
       $uid = mysqli_insert_id($db_conx); 
            $sql .= "INSERT INTO courseprogress (id, product_id_array, email, username) VALUES ('$uid','$custom','$payer_email','$username')";
            $query = mysqli_query($db_conx, $sql);
   //

我试过使用两个单独的语句,比如这个

$sql = "INSERT INTO transactions (product_id_array, email, first_name, last_name, payment_date, mc_gross, payment_currency, txn_id, receiver_email, payment_type, payment_status, txn_type, payer_status, address_street, address_city, address_state, address_zip, address_country, address_status, notify_version, verify_sign, payer_id, mc_currency, mc_fee, ip, username)       
       VALUES('$custom','$payer_email','$first_name','$last_name','$payment_date','$mc_gross','$payment_currency','$txn_id','$receiver_email','$payment_type','$payment_status','$txn_type','$payer_status','$address_street','$address_city','$address_state','$address_zip','$address_country','$address_status','$notify_version','$verify_sign','$payer_id','$mc_currency','$mc_fee','$ip','$user_name')";
$query = mysqli_query($db_conx, $sql);
//added as addition for newsletter signup below
            $uid = mysqli_insert_id($db_conx); 
            $sqlemail = "INSERT INTO courseprogress (id, product_id_array, email,username) VALUES ('$uid','$custom','$payer_email','$username')";
            $query = mysqli_query($db_conx, $sqlemail);
   //

我只能通过较低的尝试获得第一个通过...任何建议?

1 个答案:

答案 0 :(得分:0)

你有$ db_conx数据在错误的地方,它需要在同一个语句中。 你升级了sql吗?...我做到了,我不得不重新配置我创建的整个项目。 创建一个保存数据或全局数据的函数,并在每次语句或函数中重新声明$ db_conx。