裏面我想知道如果你能幫助我與我的PHP函數遞增一個PHP函數
我創建了使用單選按鈕和一個提交按鈕進行測驗。我希望函數檢查是否選擇了一個特定的單選按鈕,如果是這樣,請在用戶分數上加1。然而,被添加沒有此功能是
function Score()
{
if(isset($_POST['correctAnswer']))
{
$answer=$_POST['correctAnswer'];
$_SESSION['score']=$userScore+1;
}
else
{
$_SESSION['score']=$_SESSION['score'];
}
}
,並在其所提交的表單
echo '<strong>'."$theQuestion".'</strong><br>';
?> <form name="correctAnswer" form method="post" action="quiz.php" onSubmit="Score()">
<?php
echo "$theAnswer1";?> <input type="radio" id="correct_answer" name="correctAnswer">
<?php
echo "<br>$theAnswer2"; ?> <input type="radio" id="wrong_answer1" name="wrongAnswer1">
<?php
echo "<br>$theAnswer3"; ?> <input type="radio" id="wrong_answer2" name="wrongAnswer2">
<?php
echo "<br>$theAnswer4"; ?> <input type="radio" id="wrong_answer3" name="wrongAnswer3">
<input type="hidden" name="score" value="userScore">
<br><input type="submit" value="Submit Answer">
</form>
希望你能幫助
什麼是'$ userScore'? –
'$ _SESSION ['score'] = $ _ SESSION ['score']'完全沒有。 – deceze