2012-03-28 9 views
1

私はapiに接続し、寄付システムからユーザーを取得し、ゲームにソケットを開いて、ユーザーに寄付金額を自動的に与えようとしています。 "SQL構文に誤りがあります.1行目で '$ r'の近くで使用するようにMySQLサーバのバージョンに対応するマニュアルを確認してください。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> 

私は、ユーザーがすでにその項目特定のデータベースに追加することで自分のランクとアイテムを与えられているかどうかを確認しようとしています。そして、彼らが2度それをしようとすると、彼らはすでに彼らのランクを与えられているというエラーが表示されます!

他の問題や潜在的な問題がある場合は、それらを自由に指摘できます。 ありがとう!

+0

クエリエディタでsql文を実行できますか?選択した列のデータ型は何ですか? – Robert

+0

あなたがそこにパスワードを残したようです。あなたがそれを保つ予定があるならば、おそらくそれを変更するべきです。 – ChrisK

+0

ちょうど2つのテキストカラム – Wth123

答えて

2

基本PHP構文エラー:

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

単一引用符で囲まれた文字列は値を補間しません。クエリとしてmysqlにリテラル$rを渡しています。

+0

Lol、そんなばかげたミス!ありがとうございました!また、非常に遅く実行され、読み込むのに約1分かかります。これはユーザーのために良く見えません。接続や何のためですか?おそらく – Wth123

+0

。ソケットのものをコメントアウトし、スピードアップしているかどうかを確認してください(おそらく)。 –

関連する問題