Search code examples
phphtmlmysqlopenidsteam

PHP, openId - Can not write into mysql


Hello I am trying to set up a game betting site. I use openId to transfer data from steam to my website. But this "bug" occured while ago. I can not write new row for each new user that connects. It was working 2 days ago. I dont think i changed anything but it is not working so something had to change. My code is quite long so I will only post the part I think is problematic. So here it is. It is supposed to write new row for new user as i said.

        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;
            }
    } 

Edit: I forgot to mention that it does not show any errors or anything. It just doesnt react and behaves like it passed. For example the session indexes are set after player log in. It just does not write into mysql.


Solution

  • Okay the problem was that I added new required column into my table. Thanks for effort Matt Clark!