我的mysql连接返回错误?

时间:2012-03-28 18:35:07

标签: php mysql sockets connection

我正在尝试连接到api并从捐赠系统中获取用户,然后打开游戏的套接字以自动向用户提供他们捐赠的金额。我需要摆脱这个错误: “您的SQL语法出错;请查看与您的MySQL服务器版本对应的手册,以便在第1行的'$ r'附近使用正确的语法”

我似乎无法看到问题是什么?这是脚本:

<?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>

我正在尝试检查用户是否已经通过在给定项目时将其添加到数据库中来获得他们的等级和项目。然后,如果他们尝试两次,他们会得到一个错误,说他们已经获得了他们的排名!

如果您发现任何其他问题或潜在问题,请随时指出。 谢谢!

1 个答案:

答案 0 :(得分:2)

基本的PHP语法错误:

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

单引号字符串不会插值。您将文字$r作为查询传递给mysql。