|
 |
|
สอบถามปัญหาคำสั่ง insert into มันไม่เข้าในฐานข้อมูล ต้องเขียนอย่างไรค่ะ |
|
 |
|
|
 |
 |
|
พี่คือว่านู๋อยากให้พี่ช่วยแนะนำหน่อยว่านู๋ควรเขียนยังไง ก้อตรงบรรทัดที่เป็นคำสั่ง For นู๋ไม่มีตาราง tblPromotionBook เหมือนโค๊ดข้างล่างนี้ แต่นู๋มี
ตาราง tblOrderItems นู๋เลยอยากตัดบรรทัดที่เป็น Promotion ทั้งหมด แล้ว Insert into เข้าตาราง tblOrderItems ควรเขียนงัยพี่ ที่นู๋เขียนมามันเข้าแค่ตาราง tblorders อย่างเดียว ส่วน tblOrderItems ไม่เข้า เลยอยากถามว่าตรงบรรทัด For ควรเขียนเงื่อนไขอย่างไรพี่ ขอบคุณค่ะ
Code (PHP)
<?php require_once("../includes/template.php") ; require_once("../includes/function.php") ;
require_once("includes/shopping_function.php");
show_header("บันทึกรายการสั่งซื้อ") ; show_menu() ; check_authen("member") ;
if ( !empty( $_POST["btnNext"] ) ) {
if ( empty($_POST["txtName"]) || empty($_POST["txtSurname"]) || empty($_POST["txtAddress"]) || empty($_POST["txtDistrict"]) || $_POST["selProvince"] == "0" || empty($_POST["txtZipcode"]) ) {
process_message( "กรอกข้อมูลไม่ครบ", "shopping_process2.php" ) ;
} else {
$dblink = connect_db() ;
$now = date( "y-m-d h:i:s" ) ;
$ship_name = $_POST["txtName"] . " " . $_POST["txtSurname"] ;
$ship_address = $_POST["txtAddress"] . " เขต/อำเภอ " . $_POST["txtDistrict"] . " จังหวัด " . $_POST["selProvince"]." รหัสไปรษณีย์ " . $_POST["txtZipcode"] ;
$insert = "INSERT INTO tblOrders (mUserName, oDateTime, oShipName, oShipAddress, oShipping, oStatus, oBill) VALUES ('" . $_SESSION["ssMember"] . "', '" . $now . "', '" . $ship_name . "', '" . $ship_address . "', '" . $_POST["hShip"] . "', 1, '" . $_POST["rdoBill"] . "') " ;
$resultSql = mysqli_query( $dblink, $insert ) ;
$affected = mysqli_affected_rows( $dblink ) ;
$orderid = mysqli_insert_id( $dblink ) ;
if ( $affected == 1 ) {
$arrItems = explode( "|", $_SESSION["cart"] ) ;
$arrQuality = explode( "|", $_SESSION["quality"] ) ;
for ( $i = 0 ; $i < count( $arrItems ) ; $i++ ) {
$sqlPB = " SELECT pbID FROM tblPromotionBook WHERE bISBN='".$arrItems[$i]."' AND ExpireDate IS NULL" ;
$resultPB = mysqli_query( $dblink, $sqlPB ) ;
$rowsPB = mysqli_num_rows( $resultPB ) ;
if ( $rowsPB > 0 ) {
$rowsPB = mysqli_fetch_array( $resultPB, MYSQL_ASSOC ) ;
$insertItems = "INSERT INTO tblOrderItems (orderID, bISBN, pbID, oiQuantity) VALUES ( '" . $orderid."', '" . $arrItems[$i] . "', '" . $rowsPB["pbID"] . "', " . $arrQuality[$i] . ") " ;
} else {
$insertItems = "INSERT INTO tblOrderItems (orderID, bISBN, oiQuantity) VALUES ( '" . $orderid."', '" . $arrItems[$i] . "', " . $arrQuality[$i] . ") " ;
}
$resultSql = mysqli_query( $dblink, $insertItems ) ;
}
unset( $_SESSION["cart"] ) ;
unset( $_SESSION["quality"] ) ;
unset( $_SESSION["Shipping"] ) ;
$msg = "บันทึกรายการสั่งซื้อเรียบร้อยแล้ว" ;
process_message( $msg, "print_orderReport.php?oid=".$orderid ) ;
}
mysqli_close( $dblink ) ;
}
}
show_footer() ; ?>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2010-09-29 12:41:07 |
By :
hatinee |
View :
1050 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$resultSql = mysqli_query( $dblink, $insertItems ) or die(mysql_error()) ;
|
 |
 |
 |
 |
Date :
2010-09-29 13:10:51 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|