2014-10-08 32 views
-2

代码:您的SQL语法有错误;检查对应于你的MySQL服务器版本正确的语法使用手动附近的视角

$sql = " 
INSERT INTO book 
    (id 
    , account_no 
    , admin_id 
    , title 
    , author 
    , edition 
    , book_publisher 
    , book_copies 
    , book_isbn 
    , print_place 
    , book_year 
    , book_pages 
    , book_price 
    , entry_date 
    ) VALUES 
    ('' 
    , '$account_id' 
    , '$admin_id' 
    , '$title' 
    , '$author' 
    , '$edition' 
    , '$publisher' 
    , '$copies' 
    , '$isbn' 
    , '$place' 
    , '$year' 
    , '$pages' 
    , '$price' 
    , '$date' 
) 
"; 

在使用此查询我收到此错误插入数据:

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 's Perspective','Randal E. Bryant','2','Prentice Hall','2','978-0136108047','USA'' at line 3

任何人都可以告诉如何解决这个错误?

+0

注射攻击仍然发生,你有危险 – 2014-10-08 08:20:00

+4

显然有一些v就像'Someone's Perspective'那样会破坏查询。使用PDO,预处理语句,转义数据等。 – 2014-10-08 08:21:46

+0

您确定ID列未在数据库中设置为auto_increment吗?如果是,则从表格和值列表中排除。 – 2014-10-08 08:22:45

回答

0

我只是用mysql的这个功能插入值

mysql_real_escape_string()

,例如:

$title = mysql_real_escape_string($_POST['title']); 

它的工作...

-2

试试这个没有插入id值:

$sql = "INSERT INTO `book` 
(`account_no`, `admin_id`, `title`, `author`, `edition`, `book_publisher`, `book_copies`, `book_isbn`, `print_place`, `book_year`, `book_pages`, `book_price`, `entry_date`) 
VALUES ('$account_id','$admin_id','$title','$author','$edition','$publisher','$copies','$isbn','$place','$year','$pages','$price','$date')"; 
1

您可以尝试用\"代替'。下面的发布商字段示例。只要申请,这将有可能“或”其他领域一样

$sql = " 
INSERT INTO book 
    (id 
    , account_no 
    , admin_id 
    , title 
    , author 
    , edition 
    , book_publisher 
    , book_copies 
    , book_isbn 
    , print_place 
    , book_year 
    , book_pages 
    , book_price 
    , entry_date 
    ) VALUES 
    ('' 
    , '$account_id' 
    , '$admin_id' 
    , '$title' 
    , '$author' 
    , '$edition' 
    , \"$publisher\" 
    , '$copies' 
    , '$isbn' 
    , '$place' 
    , '$year' 
    , '$pages' 
    , '$price' 
    , '$date' 
) 
"; 
相关问题