Jump to content

What did i do wrong?


Terminaxx

Recommended Posts

So.. once again i am trying to finish my script. But something doesnt seem to work.

if ($_SERVER["REQUEST_METHOD"] == "POST") {
     $amount = input($_POST["amount"]);
        if(!empty($_POST["bet"]) and !empty($amount)){ 
                $in = input($_POST["bet"]);
                $teile = explode("#", $in);
                $game = $teile[0]; 
                $bet = $teile[1]; 
                
                $res = mysqli_fetch_object(mysqli_query($con, "SELECT * FROM games WHERE id = $game"));

                if (!empty($res)) {
                   ...
                    ...
                       ...
                        $correct= "Success";
                    }else{
                        $error = "Not enough money";
                    }
                }else{
                    $error = "Game does not exist";
                }
            }
       }else{
            $error = "Please enter the amount you want to bet";
   }
 }
$res = mysqli_query($con, "SELECT * FROM games WHERE date >= NOW() ORDER BY date ASC");

while($row = mysqli_fetch_object($res)) {
										
$id1 = $row->id."#1";
$idx = $row->id."#x";
$id2 = $row->id."#2";

echo "<tr class='tablerow'>";
    echo "<td value='$id1' name='bet' >".$row->quote1."</button></td>";

    echo "<td value='$idx' name='bet' >".$row->quotex."</button></td>";

    echo "<td value='$id2' name='bet' >".$row->quote2."</button></td>";
echo "</tr>";
}

It always causes the error "Game does not exist"

 

I think i did something wrong with "explode" but Im not sure what exactly.

 

I have omitted some unimportent elements here, if you need more information about something, just ask for it.

 

 

And before someone asks, it has nothing to do with real money and its just a project to learn more things about php and co. 

Thanks for any help. 

Link to comment
Share on other sites

You're HTML doesn't make any sense. <td> tags don't have a name or value, and you have an unmatched </button> tag. You seem to have forgotten the opening button tag.

 

 echo "<td><button value='$id1' name='bet' >".$row->quote1."</button></td>";

While your learning you should learn about PDO and parameter binding to make working with your database easier and more secure.

Link to comment
Share on other sites

As i said i cut a little bit off. Seems like a bit too much. But thats not the problem. Just assume everything is fine. I am pretty sure its because of the explode.

 

I think this doesnt work to explode:

$id1 = $row->id."#1";
$idx = $row->id."#x";
$id2 = $row->id."#2";

 

What do you think about it?

Link to comment
Share on other sites

Just assume everything is fine.

 

You must be marvellous at debugging. ::)

 

No, let's not assume everything is fine. If you want help, then it's your job to provide the facts, not show a random snippet and tell us that's where the error is. If you knew where the error is, you wouldn't be here.

 

Or you can spend the rest of the day staring at your explode() calls, if you like.

Link to comment
Share on other sites

It seems pretty clear that your problem is with the query:

 

$res = mysqli_fetch_object(mysqli_query($con, "SELECT * FROM games WHERE id = $game"));
 

The way you have written this, there are a number of things that could go wrong here including:

  • No valid $con
  • $game variable is empty
  • SQL statement is invalid
  • No result, hence nothing to fetch
See if this helps you understand what is happening:

 

 

mysqli_report(MYSQLI_REPORT_ALL);
try {
    $res = mysqli_fetch_object(mysqli_query($con, "SELECT * FROM games WHERE id = $game"));
} catch (Exception $e) {
    echo 'ERROR:'.$e->getMessage();
}
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.