1
我有一組三個單選按鈕,我需要預先選擇用戶是否已經提交(即每個用戶只有1條記錄)。我使用我知道正常工作的查詢設置了三個變量,但單選按鈕中的代碼無法識別它們。任何幫助或指導,非常感謝。這裏是PHP代碼:通過查詢未被識別設置的變量
$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);
}
}
,這裏是單選按鈕代碼:
<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>
Mawia,當我使用它的代碼,我得到了一個「未定義變量錯誤」爲$水庫當我到達即使用戶創造了一個記錄形式。任何想法爲什麼$ res是未定義的? – user3367183