Php Data can be obtained but cannot be written to the same database file. Another table may be written
Last Update:2014-03-27
Source: Internet
Author: User
Php Data can be obtained but cannot be written to the same file in the database. Another table may be written to & lt ;? Php & nbsp;/* & nbsp; order submission and processing page & nbsp; */& nbsp; // session_id (SID); & nbsp; // & nbsp; session_start (); & nbsp; require_once (".. /connect/c php Data can be obtained but cannot be written to the same file in the database. Another table may be written
// Session_id (SID );
// Session_start ();
Require_once ("../connect/conn_ SQL .php"); // contains the database link file
If ($ _ POST ["txt_taker"]! = "" & $ _ POST ["txt_address"]! = "" & $ _ POST ["txt_tel"]! = "" & $ _ POST ["txt_paymethod"]! = ""){
$ Taker = $ _ POST ["txt_taker"]; // receiver
$ Address = $ _ POST ["txt_address"]; // receiving address
$ Tel = $ _ POST ["txt_tel"]; // contact number
$ Paymethod = $ _ POST ["txt_paymethod"]; // payment method
$ Username = $ _ POST ["txt_username"]; // member name
$ Pnums = $ _ POST ["txt_pnums"]; // quantity of items
$ Omoney = $ _ POST ["txt_omoney"]; // order amount
$ Remark = $ _ POST ["txt_remark"]; // remarks
$ Onum = date ('ymdhis '). $ username; // Generate the order number
$ Createtime = date ('Y-m-d H: I: s'); // order submission date
$ Str1 = "insert into tb_order (M_Name, O_Num, P_Nums, O_Money, O_Taker, O_Address, O_Tel, O_Paymethod, O_CreateTime, O_Status, O_Remark)
Values ('$ username',' $ onum', $ pnums, $ omoney, '$ taker', '$ address', '$ tel', '$ paymethod ', '$ createtime', 0,' $ remark ')";
Echo $ str1;
$ Insert1 = mysql_query ($ str1); // execute an SQL statement
Echo $ insert1; // add to order item detail table
Session_start ();
$ Array = explode ("@", $ _ SESSION ['producelist']);
$ Arrayquatity = explode ("@", $ _ SESSION ['quatity ']);
$ S = 0;
$ I = 0;
For ($ I = 0; $ I If ($ s! = 0 ){
For ($ I = 0; $ I $ Pid = $ array [$ I]; // product ID
$ SQL = "select * from tb_product where P_ID =". $ pid; $ arr = mysql_query ($ SQL); $ info = mysql_fetch_array ($ arr );
$ Onum = date ('ymdhis '). $ username;
$ P_unitprice = $ info ['p _ vprice']; // unit price
$ P_nums = $ arrayquatity [$ I]; // quantity
$ P_price = $ arrayquatity [$ I] * $ info ['p _ vprice']; // Subtotal price
$ Str2 = "insert into tb_order_product (O_Num, P_ID, P_UnitPrice, P_Nums, P_Flod, P_Price) values ('$ onum', $ pid, $ p_unitprice, $ p_nums, 1, $ p_price) "; $ insert2 = mysql_query ($ str2); // execute an SQL statement
}
}
If ($ insert1 & $ insert2) // if data in both tables is successfully inserted
{
$ _ SESSION ['qk'] = "yes"; // clear the shopping cart
Echo "script" alert ('Congratulations, the order has been submitted! '); Window. location. href =' ../db_zhuyegoujia.php 'script ";}
Else {echo "script" alert ('sorry, order submission failed! '); Window. location. href =' ../db_member_order_add.php 'script ";
}
}
Else {echo "script" alert ('enter the required information with the * sign! '); Window. location. href =' ../db_member_order_add.php 'script ";