第1行的MYSQL错误 - 但phpmyadmin说没有错误

时间:2015-02-19 13:36:48

标签: php mysql

继承我的SQL查询

INSERT INTO `TABLE` SET `cdOwnerId` = '0', `cdArtist` = 'Amarillo', `cdTitle` = 'Tony Christie', `cdOrder` = '1', `cdType` = 'album', `cdNotes` = 'MAKE THIS WORK LATER', `cdId` = '0006', `cdObtainable` = '8'; 

INSERT INTO `TABLE` SET `cdOwnerId` = '0', `cdArtist` = 'My Way', `cdTitle` = 'Frank Sinatra', `cdOrder` = '2', `cdType` = 'album', `cdNotes` = 'MAKE THIS WORK LATER', `cdId` = '0001', `cdObtainable` = '8'; 

INSERT INTO `TABLE` SET `cdOwnerId` = '0', `cdArtist` = 'Piano concerto 21', `cdTitle` = 'Mozart', `cdOrder` = '3', `cdType` = 'album', `cdNotes` = 'MAKE THIS WORK LATER', `cdId` = '0003', `cdObtainable` = '8';

我得到的结果是......

您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便使用“&INSER INTO TABLE SET cdId =' 0',cdArtist ='我的方式',`m'在第1行

但是通过phpMyAdmin,它需要它,但通过PHP,nope ...

更新

仍然没有..

 INSERT INTO `TABLE` (`cdOwnerId`, `cdArtist`,`cdTitle`, `cdOrder`, `cdType`, `cdNotes`, `cdId`, `cdObtainable`) VALUES ('2', 'Time to say goodbye', 'Katherine Jenkins', '1', 'album', 'MAKE THIS WORK LATER', '0005', '8'),('2', 'Piano concerto 21 andante', 'Mozart', '2', 'album', 'MAKE THIS WORK LATER', '0003', '8'),('2', 'Wind Beneath My Wings', 'Bette Midler', '3', 'album', 'MAKE THIS WORK LATER', '0002', '8');

您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在'之后使用正确的语法(' 2','时间说再见',' Katherine Jenkins&# 39;,' 1','专辑','做这项工作'在第1行

表结构......

`musicCdsId` int(8) NOT NULL,
`cdOwnerId` int(20) NOT NULL,
`cdArtist` varchar(250) NOT NULL,
`cdTitle` varchar(250) NOT NULL,
`cdOrder` tinyint(2) NOT NULL,
`cdType` varchar(10) NOT NULL,
`cdNotes` varchar(250) NOT NULL,
`cdId` varchar(11) NOT NULL,
`cdObtainable` tinyint(1) NOT NULL,
`cdCost` int(5) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

循环多个cds

if(isset($_POST['musicDetails']) && is_array($_POST['musicDetails'])){
        $orderCount = 1;
        foreach($_POST['musicDetails'] as $detail){
            if(!empty($detail['title']) || !empty($detail['artist'])){
                if(!empty($cdDetails)){$cdDetails .= ",";}
                $cdDetails .= "(".dbsafe(mysql_insert_id()).", ".dbsafe($detail['artist']).", ".dbsafe($detail['title']).", ".dbsafe($orderCount).", ".dbsafe($detail['order']).", ".dbsafe("MAKE THIS WORK LATER").", ".dbsafe($detail['mycdid']).", ".dbsafe(8).")";
                $orderCount++;
            }
        } 
    }   

4 个答案:

答案 0 :(得分:1)

如果使用'INSERT INTO table-name SET',则没有问题。 虽然更常用的是'UPDATE SET'和'INSERT INTO table-name(column-names ...)VALUES(...)'。这里,SET子句明确指出列名。

这里的问题可能有所不同(因为我不确定cdOwnerId / cdId的数据类型是int还是其他任何东西)。在某些情况下,'integer'数据类型不接受值插入的字符方式(cdOwnerId ='0',cdId ='0006')。

您可以尝试将其替换为(cdOwnerId = 0,cdId = 6)并检查

http://mysqlrockstar.blogspot.in/

答案 1 :(得分:0)

更新:试试这个:

INSERT INTO `TABLE` 
(`cdOwnerId`, `cdArtist`, `cdTitle`, `cdOrder`, `cdType`, `cdNotes`, `cdId`, `cdObtainable`)
VALUES
('0', 'Amarillo', 'Tony Christie', '1', 'album', 'MAKE THIS WORK LATER', '0006', '8'),
('0', 'My Way', 'Frank Sinatra', '2', 'album', 'MAKE THIS WORK LATER', '0001', '8'),
('0', 'Mozart', 'Piano concerto 21', '2', 'album', 'MAKE THIS WORK LATER', '0003', '8');

答案 2 :(得分:0)

尝试另一种方法:

INSERT INTO `TABLE` (`cdOwnerId`, `cdArtist`, `cdTitle`, `cdOrder`, `cdType`, `cdNotes`, `cdId`, `cdObtainable`) VALUES (0, 'Amarillo', 'Tony Christie', 1, 'album', 'MAKE THIS WORK LATER', '0006', 8);

首选,在PHP脚本中,使用'而不是`

答案 3 :(得分:0)

修复实际上是不使用'在循环中...

.dbsafe($详细[艺术家])。

去图!