php - HTML Form stops working when I add another form
Get the solution ↓↓↓I have a php function echo out a form if specific parameters are met and everything was working perfectly. After I added the a few more forms under the original form (the php code is almost identical if it matters and the action parameter goes to the same file for them all) the forms above the most recently added form stops working. It continues to show up but the action param does not do anything. I have not seen anything like this before and have no idea how to handle it.
First From and if statements
<?php
$res1 = $_GET['g1'];
if ($res1 === 'true') {
$sql = "SELECT gameNumber FROM mainBets WHERE userNumber=?";
$stmt = mysqli_stmt_init($sportsbetsconn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sql_error");
exit();
}
mysqli_stmt_prepare($stmt, $sql);
mysqli_stmt_bind_param($stmt, "s", $_SESSION['userid']);
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_assoc($results);
if(in_array("1",$row) ){
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>';
}
}
?>
Second Form and if statements
<?php
$res2 = $_GET['g2'];
if ($res2 === 'true'){
$sql = "SELECT gameNumber FROM mainBets WHERE userNumber=?";
//$stmt = $sportsbetsconn->query($sql);
$stmt = mysqli_stmt_init($sportsbetsconn);
// $result = mysqli_stmt_get_result($stmt);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php?error=sql_error");
exit();
}
mysqli_stmt_prepare($stmt, $sql);
mysqli_stmt_bind_param($stmt, "s", $_SESSION['userid']);
mysqli_stmt_execute($stmt);
$results = mysqli_stmt_get_result($stmt);
$row = mysqli_fetch_assoc($results);
if(in_array("2",$row) ){
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>';
}
}
?>
Edit
Thank you to everyone that caught the missing</form>
tag that solves the main problem.
Answer
Solution:
Looks like there your code is missing a closing form tag.
Please try updating your echo to this:
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>';
Also adjust the second file accordingly.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: you must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.