 |
syntax error ช่วยดูหน่อยครับ ไม่รู้ว่าเกิดจากสาเหตุใดครับ |
|
 |
|
|
 |
 |
|
ผมใช้คลาสของลิ้งค์นี้ในการเขียนครับ
https://www.thaicreate.com/community/php-mysql-connection-class.html
โดยประยุกต์เล่นๆ ใช้กับสคริปชุดนี้ของ Admin ครับ
https://www.thaicreate.com/free-web-script/php-shopping-cart-session-array.html
ทีนี้มันเกิด error ขึ้นมาครับ โดยผมงงว่ามันเกิดจากอะไร ทั้งที่เขียนครบหมดแล้วครับ
ปัญหาน่าจะเป็นที่ syntax แต่พยายามไล่หาดูแล้วก็ไม่เจอครับ รบกวนช่วยชี้แนะนำหน่อยครับ
มันขึ้น error ว่า
Quote:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''orders' (`OrderDate`,`Name`,`Address`,`Tel`,`Email`) VALUES ('2014-02-28 07:59:' at line 1
Code (PHP)
session_start();
include ("./mysql.php");
$Total = 0;
$SumTotal = 0;
$columns = array('OrderDate','Name','Address','Tel','Email');
$values = array(date('Y-m-d H:i:s'),$_POST['txtName'],$_POST['txtAddress'],$_POST['txtTel'],$_POST['txtEmail']);
$mysql->query(
"INSERT INTO 'orders' (%q) VALUES (%s)",
array($columns, $values)
);
for($i=0;$i<=(int)$_SESSION["intLine"];$i++)
{
if($_SESSION["strProductID"][$i] != "")
{
$strSQL = $mysql->query("
INSERT INTO
'orders_detail'
VALUES
($s,$s,$s)
",
array (
$strOrderID,
$_SESSION['strProductID'][$i],
$_SESSION['strQty'][$i],
)
);
}
}
$mysql->close();
session_destroy();
header("location:finish_order.php?OrderID=".$strOrderID);
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2014-02-28 14:07:31 2014-02-28 14:07:48
|
 |
 |
 |
 |
Date :
2014-02-28 14:06:43 |
By :
ru |
View :
781 |
Reply :
9 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เห็นครับ แต่งงว่า syntex มันผิดยังไงครับ
|
 |
 |
 |
 |
Date :
2014-02-28 14:31:09 |
By :
ru |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ฟิลด์ OrderDate เป็นอะไรครับ datetime ใช่มั๊ย
ถ้าใช่คุณต้องใส่ให้ตรงกับรูปแบบของชนิดข้อมูลซิครับ 
|
 |
 |
 |
 |
Date :
2014-02-28 14:37:03 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เหมือนกันครับ ตรงชื่อฟิลด์ด้วย
'OrderDate','Name','Address','Tel','Email'
แก้เป็น
OrderDate,Name,Address,Tel,Email
เอา single quote ออกด้วย
|
 |
 |
 |
 |
Date :
2014-02-28 15:22:51 |
By :
sakuraei |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองรันแล้วครับ เอา single quote ออกปุ๊บ รันได้สำเร็จเลยครับ
|
ประวัติการแก้ไข 2014-02-28 15:28:40
 |
 |
 |
 |
Date :
2014-02-28 15:28:09 |
By :
ru |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากๆ ครับ
|
 |
 |
 |
 |
Date :
2014-02-28 15:49:04 |
By :
ru |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|