2012-03-02 134 views
0

不是一個真正的mysql專家=(我需要更多的眼睛來檢查我的查詢,只是一個看,我知道它可能很容易爲你所有,但它花了我的4小時,沒有任何result.Or建議調試這類問題的一些好的方法,在此先感謝=)使用IP地址的Mysql查詢無法插入數據庫

IP地址的可疑點造成的錯誤

我使用$ip=$_SERVER['REMOTE_ADDR']獲得IP地址和存儲在一個16位數字長度varchar與utf8 unicode ci

INSERT INTO topup 
customer_id, package_id, type, amount, slip, bank, method, description, 
approval_ip, admin_id, status) 
VALUES(1, 2, 1, 200000, example.png, CIMB, Bank In, 
Description will store your additional infomation... , 175.145.207.112, 1, 0) 

這是錯誤消息。

Error: 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 'Description will store your additional infomation about this request,175.145.207' at line 2

回答

2

不只是IP是問題,任何文本字段都是。你必須正確引用這些值。

格式的INSERT語句來是這樣的:

INSERT INTO topup (
    customer_id, package_id, type, amount, 
    slip, bank, method, description, 
    approval_ip, admin_id, status 
) VALUES (
    '1', '2', '1', '200000', 
    'example.png', 'CIMB', 'Bank In', 
    'Description will store your additional infomation...', 
    '175.145.207.112','1','0'); 

整數值不需要引號,但是你不這樣做是錯誤的,如果你與每一個價值使用他們。

2

您應該添加IP =>175.145.207.112引號,如:

 
'175.145.207.112' 
1

運行此查詢!!!,

 INSERT INTO topup 
    (customer_id,package_id,type,amount, 
slip,bank,method,description,approval_ip,admin_id,status) 
VALUES(1,2,1,200000,'example.png','CIMB','Bank In', 
'Description will store your additional infomation... ','175.145.207.112',1,0) 

真正的整數。你不需要查詢中的單引號或雙引號,

對於字符u必須使用查詢中的單引號或雙引號,