I have a set of three radio buttons that I need to preselect if the user has already made a submission (i.e. only 1 record per user). I set the three variables using queries that I know are working correctly, but the code in the radio button isn't recognizing them. Any help or guidance is greatly appreciated. Here is the php code:
$query = "SELECT * ";
$query .= "FROM mypicks ";
$query .= "WHERE user_id = {$user_id} ";
$result = mysqli_query($connection, $query);
if ($result->num_rows === 1) {
$anthem1 = mysqli_query($connection, "SELECT anthem1 FROM mypicks WHERE user_id = '$user_id'");
$cointoss2 = mysqli_query($connection, "SELECT cointoss2 FROM mypicks WHERE user_id = '$user_id'");
$firstscore3 = mysqli_query($connection, "SELECT firstscore3 FROM mypicks WHERE user_id = '$user_id'");
if (isset($_POST['submit'])) {
if (isset($_POST['anthem1'])) {
$anthem1 = $_POST['anthem1'];
}
if (isset($_POST['cointoss2'])) {
$cointoss2 = $_POST['cointoss2'];
}
if (isset($_POST['firstscore3'])) {
$firstscore3 = $_POST['firstscore3'];
}
$query = "UPDATE mypicks SET ";
$query .= "anthem1 = '{$anthem1}', ";
$query .= "cointoss2 = '{$cointoss2}', ";
$query .= "firstscore3 = '{$firstscore3}' ";
$query .= "WHERE user_id = {$user_id} ";
$result = mysqli_query($connection, $query);
}
}
And here is the radio button code:
<form action="Game1_MyPicks.php" method="post">
Will the National Anthem be over 3 mins and 15 secs? <br />
Over <input type="radio" name="anthem1" value="Over" <?php if ($anthem1=="Over") print('checked="checked"') ?>/><br />
Under <input type="radio" name="anthem1" value="Under" <?php if ($anthem1=="Under") print('checked="checked"') ?>/><br />
<br />
<br />
<br />
Which team will win the coin toss? <br />
Ravens <input type="radio" name="cointoss2" value="Ravens" <?php if ($cointoss2=="Ravens") print('checked="checked"') ?>/><br />
Niners <input type="radio" name="cointoss2" value="Niners" <?php if ($cointoss2=="Niners") print('checked="checked"') ?> /><br />
<br />
<br />
<br />
Will the first score of the game be a FG? <br />
Yes <input type="radio" name="firstscore3" value="Yes" <?php if ($firstscore3=="Yes") print('checked="checked"') ?>/><br />
No <input type="radio" name="firstscore3" value="No" <?php if ($firstscore3=="No") print('checked="checked"') ?> /><br />
<input class="button-md" type="submit" name="submit" value="Save">
</form>