Terminaxx Posted June 17, 2017 Share Posted June 17, 2017 (edited) 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. Edited June 17, 2017 by Terminaxx Quote Link to comment Share on other sites More sharing options...
kicken Posted June 17, 2017 Share Posted June 17, 2017 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. Quote Link to comment Share on other sites More sharing options...
Terminaxx Posted June 18, 2017 Author Share Posted June 18, 2017 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? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 18, 2017 Share Posted June 18, 2017 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted June 18, 2017 Share Posted June 18, 2017 Ok - I'll bite and hope I'm not looking too idiotic. What does this mean: input($_POST["amount"]); I couldn't find an "input" function in the manual, so I'm at a loss Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted June 18, 2017 Share Posted June 18, 2017 It's a custom function which probably performs useless trimming/escaping/“sanitizing”. Messing with the user input is somehow very popular in the PHP community. 1 Quote Link to comment Share on other sites More sharing options...
gizmola Posted June 18, 2017 Share Posted June 18, 2017 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(); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.