gpt4 book ai didi

php - 我的 mysql 连接返回错误?

转载 作者:行者123 更新时间:2023-11-29 07:01:37 24 4
gpt4 key购买 nike

我正在尝试连接到一个 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>

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

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

最佳答案

基本的 PHP 语法错误:

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

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

关于php - 我的 mysql 连接返回错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9913644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com