PHP data can be obtained but cannot be written to the same file as the database another table may write

Source: Internet
Author: User
session_id (SID);
Session_Start ();
Require_once (".. /connect/conn_sql.php "); Include database link file
if ($_post["Txt_taker"]!= "" && $_post["txt_address"]!= "" && $_post["Txt_tel"]!= "" && $_post[" Txt_paymethod "]!=" ") {
$taker = $_post["Txt_taker"]; Consignee
$address = $_post["txt_address"]; Shipping Address
$tel = $_post["Txt_tel"]; Contact phone
$paymethod = $_post["Txt_paymethod"];//payment method
$username = $_post["Txt_username"]; Member name
$pnums = $_post["Txt_pnums"]; Number of goods
$omoney = $_post["Txt_omoney"]; Order Amount
$remark = $_post["Txt_remark"]; Note
$onum = Date (' Ymdhis '). $username; Generate Order Number
$createtime = Date (' y-m-d h:i:s ');; Order Submission Date
$str 1 = "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 $str 1;
$insert 1 = mysql_query ($str 1); Execute SQL statement
echo $insert 1; Add to order Product 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 number
$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]; Number
$p _price = $arrayquatity [$i]* $info [' P_vprice ']; Subtotal Price
$str 2 = "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) "; $insert 2 = mysql_query ($str 2); Execute SQL statement
}
}
if ($insert 1 && $insert 2)//If data for both tables is inserted successfully
{
$_session[' qk '] = "yes"; Empty shopping Cart
echo "";}
else {echo "";
}
}
else {echo "";
}
?>


Reply to discussion (solution)

Echo Mysql_error (); Read the newspaper what's wrong

Echo Mysql_error (); Read the newspaper what's wrong

Thank you for having solved the database problem ~ ~ ~

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.