我想在'select'中保存一個選擇,但它不起作用。在提交按鈕上鍵入時,選擇不會在「選擇」中顯示舊值。驗證後在選擇HTML中保存一個值
這裏的函數的代碼:
function afficher_cours($cxn) {
$requete="SELECT ID_COURS, SIGLE FROM COURS ORDER BY SIGLE";
$res = mysqli_query($cxn, $requete);
echo '<select name = "cours">';
while($ligne = mysqli_fetch_array($res)){
if(isset($_POST[$cours]) AND ($_POST[$cours] == $ligne)) {
$selected = 'selected="selected"';
} else {
$selected='';
}
echo "<option value = $ligne[0] $selected > $ligne[1] </option>";
}
echo '</select>';
}
這裏的腳本代碼:
<form method="POST" action="">
<table>
<tr>
<td> Classe </td>
<td>
<?php afficher_classe() ?>
</td>
<td> Cours </td>
<td> <?php afficher_cours($cxn) ?> </td>
<td> Numéro du test </td>
<td> <?php selection_noTest(0, 5, 'noTest'); ?> </td>
<td>
<input type="SUBMIT" name="afficher" value="Afficher"/>
</td>
</tr>
</table>
if(isset($_POST['afficher'])) {
$cours = $_POST['cours'];
$classe = $_POST['classe'];
$noTest = $_POST['noTest'];
$annee = ANNEE;
$_SESSION['cours'] = $cours;
$_SESSION['noTest'] = $noTest;
$requete = "SELECT NBTESTS, EXAMEN FROM COURS WHERE ID_COURS = $cours";
$res = mysqli_query($cxn, $requete);
echo (mysqli_error ($cxn));
$ligne = mysqli_fetch_array($res);
$_SESSION['nbTests'] = $ligne['NBTESTS'];
$_SESSION['examen'] = $ligne['EXAMEN'];
if (($noTest > $ligne['NBTESTS']) OR (($noTest == 0) AND ($ligne['EXAMEN'] == 'non'))) {
echo 'Le numéro du test est incorrect pour ce cours. <br/>';}
感謝您的幫助提前!
在一個函數中,我試圖用'$ ligne'''ID_ELEVE'''取代'$ ligne',但它不起作用。 – Sab25 2014-09-24 07:36:23