在DUPLICATE KEY UPDATE我做错了什么_

时间:2018-01-19 08:23:14

标签: php mysql

当我尝试通过PHP将数据发布到SQL中时,我在网页上收到错误消息:

  

错误:插入INTO mydata(uke,man1,tir1,colman1,coltir1)VALUES('7','','','','')ON DUPLICATE KEY UPDATE man1 =,tir1 =,colman1 =, coltir1 =   您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第14行'tir1 ='附近使用正确的语法

$uke = $_POST[uke];
$man1 = $_POST[man1];
$tir1 = $_POST[tir1];
$colman1 = $_POST[colman1];
$coltir1 = $_POST[coltir1];



  $sql = "insert INTO mydata  ( uke,  
  man1, tir1, 
  colman1, coltir1)
  VALUES 
  ( 
  '$uke',
  '$man1','$tir1',
  '$colman1','$coltir1')
ON DUPLICATE KEY UPDATE 
man1 = $man1,
tir1 = $tir1,
colman1 = $colman1,
coltir1 = $coltir1";

SQL是:

uke int(11) No  Primary NULL    
timer   float(255,2)    Yes None    NULL    
man1    decimal(20,2)   Yes None    NULL    
tir1    decimal(20,2)   Yes None    NULL    
colman1 varchar(255)    Yes None    NULL
coltir1 varchar(255)    Yes None    NULL

任何人都可以给我一个提示(或告诉我)我有错误吗?

2 个答案:

答案 0 :(得分:1)

column names

试试这个。

答案 1 :(得分:0)

查询应该像这样更新。

$sql = "insert INTO mydata  ( uke,  man1, tir1, colman1, coltir1)
                  VALUES ( '$uke','$man1','$tir1', '$colman1','$coltir1')
                ON DUPLICATE KEY UPDATE 
                man1 = '$man1',
                tir1 = '$tir1',
                colman1 = '$colman1',
                coltir1 = '$coltir1'";