2012-03-01 65 views
0

我無法得到這個編譯正確。使用PHP插入到MySQL數據庫的某些領域

$username = mysql_real_escape_string($_GET['username']); 
$about = mysql_reaL_escape_string($_GET['about']); 
$icebreaker = mysql_reaL_escape_string($_GET['icebreaker']); 


$query = "UPDATE '$mysql_database'.main SET about = '$about', icebreaker = '$icebreaker' WHERE username = '$username';"; 

我得到的錯誤

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 ''a4396957_users'.main 
SET about = 'testing', icebreaker = 'ice' WHERE us' at line 1 

有缺這個說法?

回答

3

不撇號,其名稱引用數據庫名稱或引用

$query = "UPDATE `$mysql_database`.`main` SET `about` = '$about', `icebreaker` = '$icebreaker' WHERE `username` = '$username';"; 

使用'而不是'

2
$query = "UPDATE $mysql_database.main SET about = '$about', icebreaker = '$icebreaker' WHERE username = '$username';"; 

內的MySQL某些對象,包括數據庫,表,索引,列,別名,視圖,存儲過程,分區,並且已知作爲標識符的其它對象名稱..

標識符引號字符是反引號(「`」)..

如果啓用了ANSI_QUOTES SQL模式,它也允許雙引號內引用標識符:

mysql> CREATE TABLE "test" (col INT); 
ERROR 1064: You have an error in your SQL syntax... 

mysql> SET sql_mode='ANSI_QUOTES'; 
mysql> CREATE TABLE "test" (col INT); 
Query OK, 0 rows affected (0.00 sec) 
+0

他們應該然而逃脫,只是不能與撇號,否則列'鎖定「或」訂單「可能會導致一些問題 – Moak 2012-03-01 17:48:41

+0

好,好的編輯;) – Moak 2012-03-01 17:58:32