2012-01-03 73 views
2
mysql_query (" 
    INSERT INTO items 
    (index, name, description, given_by, 
    cost_to_tcs, starting_bid, auction_type) 
    VALUES 
    ('{$index_number}','{$name}','{$description}','{$donated_by}', 
    NULL,'{$auction_type}','{$starting_bid}') 
    ") 
    or die("3: " . mysql_error()); 

错误有:是什么导致这个mysql查询错误?

3:你在你的SQL语法错误;检查与您的MySQL服务器版本相对应的手册,以便在第1行的''index','name','description','given_by','cost_to_tcs','starting_bid','auct'附近使用正确的语法。

感谢您的帮助。

回答

8

index是mysql的保留关键字,包裹index用(反勾)```

INSERT INTO items 
(`index`, `name`, `description`, `given_by`, 
    `cost_to_tcs`, `starting_bid`, `auction_type`) 

Reserve key words

+1

谢谢!这使得从现在起,我可以停止将我的头撞在墙上! – lampwins 2012-01-03 05:21:46

1

尝试这样的:

mysql_query (" 
INSERT INTO items (
    `index`, 
    `name`, 
    `description`, 
    `given_by`, 
    `cost_to_tcs`, 
    `starting_bid`, 
    `auction_type`) 
VALUES(
    '$index_number', 
    '$name', 
    '$description', 
    '$donated_by', 
    NULL, 
    '$auction_type', 
    '$starting_bid') 
") 
or die("3: " . mysql_error()); 

也确保安全的数据与mysql_real_escape_string();

相关问题