2011-03-16 56 views
-3

我有以下錯誤在查詢請告訴我錯誤PLS解決它

插入到staff_service(CUSTOMER_ID,workorder_no,service_date,CURRENT_DATE)值( '1', '414','2011-03-14 ',CURDATE())1064你的SQL語法有錯誤;在第1行檢查對應於您的MySQL服務器版本的手冊,查看'current_date'值('1','414','2011-03-14',CURDATE())'以使用正確的語法。

表名後
<?php 
session_start(); 

include "common/config.php"; 

    $file=file("Template/staffservice_management.html"); 
    $filecontent=join("",$file); 
    include("user.php"); 
/*$sql = "SELECT id,customer_name FROM customer "."ORDER BY customer_name"; 

$rs = mysql_query($sql); 

while($row = mysql_fetch_array($rs)) 
{ 
    echo "<option value=\"".$row['id']."\">".$row['customer_name']."</option>"; 
    echo "<option value=\"".$row['id']."\">".$row['customer_name']."</option>"; 
    echo "<option value=\"".$row['id']."\">".$row['customer_name']."</option>"; 
}*/ 
$sql="select * from customer"; 
$res=mysql_query($sql); 
while($row=mysql_fetch_array($res)) 
{ 
    $list_option.="<option value='".$row['id']."'>".$row['customer_name']."</option>"; 
} 
$cust=$_POST['cname']; 
$work=$_POST['won']; 
$date=$_POST['startdate']; 
if($_REQUEST['submit']=='submit') 
{ 
$sqle=("insert into staff_service(customer_id,workorder_no,service_date,current_date) values('$cust','$work','$date',CURDATE())"); 
$Insertprocess=$db->insert_data_id($sqle); 
echo "<script>alert(' Details Successfully created');</script>;"; 
echo "<script>location.href='staffservice_management.php';</script>;"; 
} 
$filecontent=preg_replace("/{{(.*?)}}/e","$$1",$filecontent); 
echo $filecontent; 

?> 
+0

什麼是你的mysql'current_date'數據類型? – kjy112 2011-03-16 13:17:08

回答

0
insert into staff_service (customer_id,workorder_no,service_date,current_date) values('$cust','$work','$date',CURDATE()) 

留出空間

0

我猜你需要

staff_service

之間的空間

(CUSTOMER_ID,workorder_no,service_date,CURRENT_DATE)

與嘗試:

$sqle=("insert into staff_service (customer_id,workorder_no,service_date,current_date) values('$cust','$work','$date',CURDATE())"); 

HTH!

-1

在SQL查詢的末尾添加一個分號。

+0

-1,因爲任何PHP MySQL庫的行爲就好像在查詢結束時會自動分號一樣。 – 2011-03-16 14:28:33

1

不要直接將變量插入SQL中,而是要求SQL注入攻擊。看看http://www.bobby-tables.com/

至於錯誤,表名後沒有空格,這是可能的罪魁禍首;它被視爲對未知函數的調用,staff_service()

+0

小Bobby Tables +1,總是讓我發笑 – 2011-03-16 13:22:13

0

你並不需要使用" ' "爲數字/ IDS:

insert into staff_service(customer_id,workorder_no, service_date,current_date) values(1,414,'2011-03-14',CURDATE()) 
0
INSERT INTO staff_service 
(customer_id,workorder_no,service_date,current_date) 
VALUES ('1','414','2011-03-14',CURDATE()) 

有一個關於Data Types幾個問題:

  • 什麼是CUSTOMER_ID的數據類型?
    • 如果它是一個INT數據類型,不需要在值的單引號1
      • 實施例:VALUES(1, '414', '2011-03-14',CURDATE())
  • workorder_no的數據類型是什麼?
    • 如果它是一個INT數據類型,不需要在值的單引號414
      • 實施例:VALUES( '1',414 '2011-03-14',CURDATE())
  • service_date的數據類型是什麼?
    • 如果是日期/時間類型,那麼您提交的格式正確?
  • 什麼是CURRENT_DATE的數據類型?
    • 如果是日期/時間類型,那麼您提交的格式正確?

你可能要結束你的SQL語句用分號爲好,像這樣:

INSERT INTO staff_service 
(customer_id,workorder_no,service_date,current_date) 
VALUES ('1','414','2011-03-14',CURDATE()); 

我的建議是,以確保您傳遞數據格式正確

相關問題