0

First mysqli_query is working just fine and is getting a result, but the second one isn't making it past the if condition, it's like $result is returning false. I saw similar questions but non of them seemed to be the problem I am looking for. I just want to point out that there is no problem in the sql statement its working fine in the database.

    session_start();
    $username = $_SESSION['username'];
    $id = $_SESSION['id'];

//FIRST SQL QUERY
            $sql = "call getrounds($id);";
            if($result = mysqli_query($conn, $sql))
            {
                while($row = mysqli_fetch_assoc($result))
                {
                    if($row['winner'] == "Player"){
                        $playerstatus="Win";
                        $botstatus="Lose";
                    }else if($row['winner'] == "Epsilon"){
                        $playerstatus="Lose";
                        $botstatus="Win";
                    }else{
                        $playerstatus="Draw";
                        $botstatus="Draw";
                    }
                    echo "<script type=text/javascript>createRow('".$username."','Epsilon',".$row['playerscore'].",".$row['botscore'].",'".$playerstatus."','".$botstatus."');</script>";
                }
                mysqli_free_result($result);
            }

//SECOND SQL QUERY
            $sql = "SELECT botwins, playerwins FROM game WHERE id=$id;";
            if($result =  mysqli_query($conn, $sql))
            {
                echo "success"; //To test if the $result is not false (its returning false).
                while($row = mysqli_fetch_row($result)) //I also tried mysqli_fetch_assoc but it didn't work.
                {
                    if($row[0] >= 10 || $row[1] >= 10){
                        $sql = "call resetgame($id);";
                        mysqli_query($conn, $sql);
                    }
                }
                mysqli_free_result($result);
            } 

When I removed the first query and left the second, the second worked just fine. Why can't I put them together?

I am not getting any errors, but I am not getting any results from the second query either.

Kamel Yehya
  • 33
  • 1
  • 8
  • 1
    _"I am not getting any errors"_... are you checking for any? Have you setup your environment to report them? – Phil May 12 '21 at 04:14
  • there was no error on the page when it ran the script, neither in the console. – Kamel Yehya May 12 '21 at 04:17
  • I think you may have misunderstood my comment. Please see [How to get the actual mysql error and fix it?](https://stackoverflow.com/a/22662582/283366) – Phil May 12 '21 at 04:24
  • You should be getting out of sync error as you are calling stored procedure without going to the next result – Dharman May 12 '21 at 08:42

0 Answers0