我为我的网站创建了一个STEAM OPENID,但有些错误。 我不知道错误是什么..有人可以帮助我......
错误:
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in D:\xampp\htdocs\PTgamersCo\steamid.php on line 69
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in D:\xampp\htdocs\PTgamersCo\steamid.php on line 73
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in D:\xampp\htdocs\PTgamersCo\steamid.php on line 76
这是我的数据库连接
$username = "root";
$password = "";
$host = "localhost";
$db = "steam_users";
$sql_steam = mysqli_connect($host, $username, $password, $db);
if (!$sql_steam) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
mysqli_close($sql_steam);
此代码将添加到DB。
foreach ($json_decoded->response->players as $player)
{
$sql_fetch_id = "SELECT * FROM users_steam WHERE steamid = $player->steamid";
$query_id = mysqli_query($db, $sql_fetch_id);
//$_SESSION['avatar'] = $player->avatar;
if(mysqli_num_rows($query_id) == 0) {
$sql_steam = "INSERT INTO users_steam (name, steamid, avatar) VALUES ('$player->personaname', '$player->steamid', '$player->avatar')";
mysqli_query($db, $sql_steam);
}
}
答案 0 :(得分:0)
所有mysqli_*
函数都要求第一个参数为mysqli_connect($host, $username, $password, $db);
调用返回的变量。
此外,您需要保持连接处于打开状态才能使用它,因此请删除DBCONNECTION脚本中的mysqli_close($db);
所以修改你的DBCONNECTION到这个
$username = "root";
$password = "";
$host = "localhost";
$dbname = "steam_users";
$db = mysqli_connect($host, $username, $password, $dbname );
if (!$db) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
// Dont close the connection, or you wont be able to use it later
//mysqli_close($db);
您的其他代码将在$db
变量