2014-10-08 35 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' 
) 
"; 
相關問題