ขอความช่วยเหลือหน่อยครับ ขึ้นแบบนี้ 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 ')
ขอความช่วยเหลือหน่อยครับ ขึ้นแบบนี้ครับ
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 ')
ส่วนนี้โค้ดครับ
<?php
if ( $_FILES['file']['error'] ) {
die("upload error ");
}
//======Connect DB======================//
$m_host = "localhost";
$m_user = "root";
$m_pass = "qwerty";
$m_name = "thaipost";
mysql_connect($m_host,$m_user,$m_pass);
mysql_select_db($m_name);
$sql="SELECT * FROM ems_data ORDER BY invoice DESC";
mysql_query("SET NAMES UTF8");
//======End Connect DB======================//
//======Get data from Excel======================//
$dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
$rows = $dom->getElementsByTagName( 'Row' );
$row = 0;
foreach ($rows as $temp) {
$col = 0;
if($row==0) {
$row++; continue;
}
$cells = $temp->getElementsByTagName('Cell');
foreach( $cells as $cell ) {
if($col==0) $data1 = $cell->nodeValue;
if($col==1) $data2 = $cell->nodeValue;
if($col==2) $data3 = $cell->nodeValue;
if($col==3) $data4 = $cell->nodeValue;
if($col==4) $data5 = $cell->nodeValue;
if($col==5) $data6 = $cell->nodeValue;
$col++;
}
//======End Get data from Excel======================//
//==================Insert To DB ====================================//
$sql = " INSERT INTO ems_data (";
$sql .= " invoice, ";
$sql .= " date, ";
$sql .= " ems, ";
$sql .= " customer, ";
$sql .= " province, ";
$sql .= " price, ";
$sql .= " ) VALUES ( ";
$sql .= " '$data1', ";
$sql .= " '$data2', ";
$sql .= " '$data3', ";
$sql .= " '$data4', ";
$sql .= " '$data5', ";
$sql .= " '$data6', ";
$sql .= " ) ";
$rs = mysql_query($sql) or die(mysql_error());
//==================End Insert To DB ====================================//
$row++;
}
mysql_close();
echo "<script>alert('Upload ข้อมูลสำเร็จแล้วครับ')</script>";
print"<meta http-equiv = 'refresh' content='0;URL=pmav.php'>";
?>Tag : PHP, MySQL
Date :
2013-08-01 11:19:01
By :
conline106
View :
737
Reply :
7
ช่วยดูหน่อยครับ
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 ') VALUES ( 'BBR/06923/201306', '2013-06-28T00:00:00.000', 'EK213571126TH', '' at line 1
เหมือนว่ามันไม่รับค่าที่เป็นภาษาไทยอะครับ
ไม่รู้ว่าจะแก้ยังไง
ขอบคุณล่วงหน้าสำหรับทุกๆคำตอบ
Date :
2013-08-01 11:42:53
By :
conline106
Code (PHP)
$sql .= " price, ";
comma เกินมาอันนึง
Date :
2013-08-01 12:08:21
By :
Manussawin
ขอบคุณมากครับ คุณ GuEm13oy
Date :
2013-08-01 12:39:00
By :
conline106
แล้วถ้าอยาก เช็คว่า ข้อมูลที่อัพไปซ้ำกับของเดิมหรือไม่ แล้วมีการแจ้งเตือน จะต้องทำอย่างไรครับ
Date :
2013-08-01 12:50:53
By :
conline106
ก็ select ข้อมูลใน Database ออกมาแล้วเปรียบเทียบกับที่จะ insert เข้าไปครับ ใช้ if else ดักเอาครับ ถ้าไม่มีก็ insert ถ้ามีก็ แจ้งเตือน
Date :
2013-08-01 13:08:10
By :
Manussawin
เดวของลองดูก่อนนะครับ
Date :
2013-08-01 13:13:20
By :
conline106
มันขึ้นแบบนี้ครับ ไม่รู้ว่าใส่ถูกที่ไหม
Duplicate entry '201306' for key 1
ส่วนนี้โค้ดครับ
<?php
if ( $_FILES['file']['error'] ) {
die("upload error ");
}
//======Connect DB======================//
$m_host = "localhost";
$m_user = "root";
$m_pass = "qwerty";
$m_name = "thaipost";
mysql_connect($m_host,$m_user,$m_pass);
mysql_select_db($m_name);
$sql="SELECT * FROM ems ORDER BY invoice DESC";
mysql_query("SET NAMES UTF8");
//======End Connect DB======================//
//======Get data from Excel======================//
$dom = DOMDocument::load( $_FILES['file']['tmp_name'] );
$rows = $dom->getElementsByTagName( 'Row' );
$row = 0;
foreach ($rows as $temp) {
$col = 0;
if($row==0) {
$row++; continue;
}
$cells = $temp->getElementsByTagName('Cell');
foreach( $cells as $cell ) {
if($col==0) $data1 = $cell->nodeValue;
if($col==1) $data2 = $cell->nodeValue;
if($col==2) $data3 = $cell->nodeValue;
if($col==3) $data4 = $cell->nodeValue;
if($col==4) $data5 = $cell->nodeValue;
if($col==5) $data6 = $cell->nodeValue;
$col++;
}
//======End Get data from Excel======================//
$sql1="SELECT * FROM ems where invoice ='$invoice'";
$query1 = mysql_query($sql1);
if(mysql_num_rows($query1) != 0){ //ซ้ำกับ record อื่นๆ
}else{ //ไม่ซ้ำ save โลด
//==================Insert To DB ====================================//
$sql = " INSERT INTO ems (";
$sql .= " invoice, ";
$sql .= " date, ";
$sql .= " ems, ";
$sql .= " customer, ";
$sql .= " province, ";
$sql .= " price ";
$sql .= " ) VALUES ( ";
$sql .= " '$data1', ";
$sql .= " '$data2', ";
$sql .= " '$data3', ";
$sql .= " '$data4', ";
$sql .= " '$data5', ";
$sql .= " '$data6' ";
$sql .= " ) ";
$rs = mysql_query($sql) or die(mysql_error());
//==================End Insert To DB ====================================//
$row++;
}
mysql_close();
echo "<script>alert('Upload ข้อมูลสำเร็จแล้วครับ')</script>";
print"<meta http-equiv = 'refresh' content='0;URL=pmav.php'>";
}
?>
Date :
2013-08-01 16:19:07
By :
conline106
Load balance : Server 04