I have multiple forms echoed out by php if specific parameters are met. If the form gets submitted, php and sql code is supposed to check a database and if the submission is found. If it is found it does not echo the form. The problem is that the php/sql that checks if the form has been submitted only works for the first form submitted and does not work for any other forms. The The PHP/SQL that submits the form answers into the database works for all of them
Form 1 with SQL and PHP
$res1 = $_GET['g1'];
//echo "{$res}";
if ($res1 === 'true') {
//echo "{$res}";
$sql1 = "SELECT gameNumber FROM mainBets WHERE userNumber=?";
//$stmt = $sportsbetsconn->query($sql);
$stmt1 = mysqli_stmt_init($sportsbetsconn);
// $result = mysqli_stmt_get_result($stmt);
if (!mysqli_stmt_prepare($stmt1, $sql1)) {
header("Location: ../index.php?error=sql_error");
exit();
}
mysqli_stmt_prepare($stmt1, $sql1);
mysqli_stmt_bind_param($stmt1, "s", $_SESSION['userid']);
mysqli_stmt_execute($stmt1);
$results1 = mysqli_stmt_get_result($stmt1);
$row1 = mysqli_fetch_assoc($results1);
if(in_array("1",$row1) ){
echo "Bet Placed";
}else{
$coins = $_SESSION['coins'];
echo '<form action="includes/placebet.inc.php" method="post">
<select name="chosenTeam">
<option value="TEAM1">TEAM11</option>
<option value="TEAM2">TEAM2</option>
</select>
<input name ="bet-amount" type="number" min="0" max="'.$coins.'">
<input name ="gameNum" type="hidden" value="1">
<button type="submit" name="bet-submit">Place Bet</button>
</form>';
}
}
Form 2 with SQL and PHP
$res2 = $_GET['g2'];
if ($res2 === 'true'){
$sql2 = "SELECT gameNumber FROM mainBets WHERE userNumber=?";
//$stmt = $sportsbetsconn->query($sql);
$stmt2 = mysqli_stmt_init($sportsbetsconn);
// $result = mysqli_stmt_get_result($stmt);
if (!mysqli_stmt_prepare($stmt2, $sql2)) {
header("Location: ../index.php?error=sql_error");
exit();
}
mysqli_stmt_prepare($stmt2, $sql2);
mysqli_stmt_bind_param($stmt2, "s", $_SESSION['userid']);
mysqli_stmt_execute($stmt2);
$results2 = mysqli_stmt_get_result($stmt2);
$row2 = mysqli_fetch_assoc($results2);
if(in_array("2",$row2) ){
echo "Bet Placed";
}else{
$coins = $_SESSION['coins'];
echo '<form action="includes/placebet.inc.php" method="post">
<select name="chosenTeam">
<option value="TEAM1">TEAM11</option>
<option value="TEAM2">TEAM2</option>
</select>
<input name ="bet-amount" type="number" min="0" max="'.$coins.'">
<input name ="gameNum" type="hidden" value="2">
<button type="submit" name="bet-submit">Place Bet</button>
</form>';
}
}
Aucun commentaire:
Enregistrer un commentaire