2011-09-05 62 views
1

所以我有這個,的MySQL(和/或)PHP問題

<?php 
require "database.php"; 

$to=$_GET['toF']; 
$content=$_POST['message_contentl']; 
$from=$_GET['fromF']; 

$ck_reciever = "SELECT Username FROM accounts WHERE username = '".$to."'";  

if(mysql_num_rows(mysql_query($ck_reciever)) == 0){ 
die("The user you are trying to contact don't exist. Please go back and try again.<br> 
<form name=\"back\" action=\"Send_FR.php\" method=\"post\"> 
<input type=\"submit\" value=\"Try Again\"> 
</form> 
"); 
}else{ 

$a1 = $_POST['message_contentl']; 
$a2 = $_GET['fromF']; 
$a3 = $_GET['toF']; 
mysql_query("INSERT INTO Friends (fr_message, From, To) VALUES ('$a1', '$a2', '$a3')");  OR die("Could not send the message: <br>".mysql_error()); 
echo "The Friend Request Was Successfully Sent!"; 
?> 

但它不工作。

它所做的就是給我這個錯誤消息:

您的SQL語法錯誤;請在第1行檢查與您的MySQL服務器版本對應的正確語法的手冊,以便使用'From,To')VALUES('','Extro','Syncro')'

請幫忙?

+0

請問fr_message列接受空值? –

+0

[由於在MySQL中使用保留字作爲表或列名而導致的語法錯誤]的可能重複(http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word -as-A-表或列名稱合的MySQL) –

回答

5

fromto是保留字在SQL,MySQL中,你可以通過在反引號包裹他們將保留字用作列或表名,但我強烈建議不要使用保留字作爲列名的,這是可怕的混亂。小例子前absurdo:

select `select`, `from` from `where` where `like` like 'like'; 

呀,發動機吃它,但你得承認它可能是更具可讀性:-)

1

FROM是一個保留的SQL關鍵字 - 如果您有一個具有該名稱的列或表,則必須反引號(')。