I’m attempting to connect to an api and get a user from a donation system and then open a socket to a game to automatically give a user the amount they donated for. I need to get rid of this error:
“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 ‘$r’ at line 1”
I can’t seem to see what the problem is? Here’s the script:
<?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>
I’m trying to check if the user has been already given their rank and items by adding them to a database when their given their items. And then if they try to do it twice they will get an error saying that they have already been given their rank!
If you see any other problems or potental problems feel free to point them out.
Thanks!
Basic PHP syntax error:
single quoted strings do not interpolate values. You’re passing a literal
$andrto mysql as a query.