2012-03-28 76 views
1

我試圖連接到api並從捐贈系統獲取用戶,然後打開遊戲套接字以自動爲用戶提供捐贈的金額。我需要擺脫這種錯誤的: 「您的SQL語法錯誤;檢查對應於你的MySQL服務器版本,在1號線附近使用‘$ R’正確的語法手冊」我的mysql連接返回錯誤?

我似乎無法看到問題是什麼?這裏的腳本:

<?php 
$tablename="CENSORED"; 
$DBUSER="CENSORED"; 
$DBPASSWORD="CENSORED"; 
$DBHOST="CENSORED"; 
?> 
<?php 

$urlMask = 'CENSORED';  

$getUser = function($id) use ($urlMask) { 
    list($user) = json_decode(file_get_contents(sprintf($urlMask, $id))); 
    return (object) $user; 
}; 

$user = $getUser(4087396); 

$Username = $user->user->username; 
$Rank = $user->item_name; 
$IGN = $user->custom_field; 
echo '<center> Your username is '.$IGN.' correct? </center> '; 
?> 

<?php 
if(isset($_POST['Clickbutton'])){ 

    $con = mysql_connect($DBHOST,$DBUSER,$DBPASSWORD); 
if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 

    } 
mysql_select_db($tablename, $con); 
$sql="SELECT IGN FROM fisktable WHERE IGN='$IGN' and Rank='$Rank'" ; 
$r = mysql_query($sql); 
if(!$r) { 
    $err=mysql_error(); 
    print $err; 
} 

    $result = mysql_query('$r') or die(mysql_error()); 
    if(mysql_num_rows($result) == 1) { 
echo 'That username has already been given their rank!'; 
    } else { 
     $HOST = "77.45----"; //the ip of the bukkit server 
     $password = "chdfxfdxh"; 
     //Can't touch this: 
     $sock = socket_create(AF_INET, SOCK_STREAM, 0) 
     or die("error: could not create socket\n"); 
     $succ = socket_connect($sock, $HOST, 4445) 
     or die("error: could not connect to host\n"); 
     //Authentification 
     socket_write($sock, $command = md5($password)."<Password>", strlen($command) + 1) 
     or die("error: failed to write to socket\n"); 
     //Begin custom code here. 
     socket_write($sock, $command = "/Command/ExecuteConsoleCommand:pex user ($IGN) group set ($Rank);", strlen($command) + 1) //Writing text/command we want to send to the server 
     or die("error: failed to write to socket\n"); 
     socket_write($sock, $command = "Thanks, ($IGN) for donating to the ($Rank) rank! ;", strlen($command) + 1) 
     or die("error: failed to write to socket\n"); 
    mysql_select_db($tablename, $con); 
$sql="INSERT INTO $tablename(IGN,Rank) VALUES ('$IGN','$Rank')" ; 
     exit(); 
}} 
?> 
<center> 
<form method="POST"> 
<input name="Clickbutton" type="submit" value="Yes! I would like to receive my rank!"/> 
</form> 
</center> 

我試圖檢查用戶是否已經通過時,他們給自己的物品將其添加到數據庫中已經給他們的級別和項目。然後,如果他們嘗試兩次,他們會得到一個錯誤,說他們已經被賦予了他們的等級!

如果您發現任何其他問題或potental問題隨時指出它們。 謝謝!

+0

你可以在查詢編輯器中運行sql語句嗎?您選擇的列的數據類型是什麼? – Robert 2012-03-28 18:37:25

+0

似乎你在那裏留下了一個密碼 - 如果你打算保留它,你可能應該改變它。 – ChrisK 2012-03-28 18:38:19

+0

只有2個文本列 – Wth123 2012-03-28 18:38:21

回答

2

基本PHP語法錯誤:

$result = mysql_query('$r') or die(mysql_error()); 
         ^--^--- remove the quotes 

單引號字符串不插入值。作爲查詢,您將字面值$r傳遞給mysql。

+0

哈哈,這樣一個愚蠢的錯誤!謝謝!它運行速度非常慢,大約需要一分鐘才能加載。這對用戶來說看起來不太好。這是因爲連接還是什麼?可能是 – Wth123 2012-03-28 18:42:17

+0

。註釋掉socket的東西,看它是否加速(可能會)。 – 2012-03-28 18:44:01