PHP,openId - 无法写入mysql

时间:2016-11-25 22:14:26

标签: php html mysql openid steam

您好我正在尝试建立一个游戏投注网站。我使用openId将数据从steam传输到我的网站。但这个“虫子”在此前发生过。我不能为每个连接的新用户写新行。它在2天前工作。我不认为我改变了什么,但它不起作用所以必须改变。我的代码很长,所以我只发布我认为有问题的部分。 所以这就是。据我所知,它应该为新用户写新行。

        if($openid->validate()) 
    {
            $id = $openid->identity;
            // identity is something like: http://steamcommunity.com/openid/id/76561197960435530
            // we only care about the unique account ID at the end of the URL.
            $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/";
            preg_match($ptn, $id, $matches);
            echo "Sucesfully logged in (steamID: $matches[1])\n";

            $url = "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=$_STEAMAPI&steamids=$matches[1]";
            $json_object= file_get_contents($url);
            $json_decoded = json_decode($json_object);

            foreach ($json_decoded->response->players as $player)
            {
                $sql_fetch_id = "SELECT * FROM users_steam WHERE steamid = $player->steamid";
                $query_id = mysqli_query($conn,$sql_fetch_id);

                if(mysqli_num_rows($query_id)==0){
                    $sql_steam = "INSERT INTO users_steam (name, steamid, avatar, loggedin, tradeurl) VALUES ('$player->personaname', '$player->steamid', '$player->avatar',' ',' ')";
                    mysqli_query($conn,$sql_steam);}

                $_SESSION["id"] = $player->steamid;
                $_SESSION["name"] = $player->personaname;
                $_SESSION["url"] = $player->profileurl;
                $_SESSION["smallavatar"] = $player->avatar;
                $_SESSION["mediumavatar"] = $player->avatarmedium;
                $_SESSION["largeavatar"] = $player->avatarfull;
            }
    } 

编辑:我忘了提及它没有显示任何错误或任何内容。它只是没有反应,表现得像它通过。例如,会话索引是在播放器登录后设置的。它只是不写入mysql。

1 个答案:

答案 0 :(得分:0)

好的问题是我在表格中添加了新的必需列。感谢Matt Clark的努力!