我不明白为什么我不能在此代码中使用我的最后一个表单。我使用SELECT列表生成了一个表单,以选择我想要更新的成员并且它有效,但我不知道为什么我不能使用此表单中的数据。实际上,我甚至无法回应一些事情(最后见echo "TEST";
,提交表格时没有任何反应。)
<?php $mysqli = new Mysqli("localhost", "root", "", "repertoire"); ?>
<form method="post" action="">
<label>Modifier</label>
<select name='id_modif'>
<?php
$resultat = $mysqli->query("SELECT * FROM annuaire");
while($select = $resultat->fetch_assoc()){
echo "<option value=". $select['id_annuaire'] . ">" . $select['prenom'] . " " . $select['nom'] . "</option>";
}
?>
</select>
<input type ="submit" name="modifier">
</form>
<br>
<?php
if (isset($_POST['modifier'])){
//print_r($_POST);
$resultat = $mysqli->query("SELECT * FROM annuaire WHERE id_annuaire = '$_POST[id_modif]'");
while ($modif = $resultat->fetch_assoc()) {
echo '<form method="post" action="">
<label for="nom">Nom *</label><br>
<input type="text" name="nom" value="' . $modif['nom'] . '"> <br>';
echo '<label for="prenom">prenom *</label><br>
<input type="text" name="prenom" value="' . $modif['prenom'] . '"> <br>';
echo '<label for="telephone">telephone *</label><br>
<input type="text" name="telephone" value="' . $modif['telephone'] . '"> <br>';
echo '<label for="profession">profession *</label><br>
<input type="text" name="profession" value="' . $modif['profession'] . '"> <br>';
echo '<label for="ville">ville *</label><br>
<input type="text" name="ville" value="' . $modif['ville'] . '"> <br>';
echo '<label for="codepostal">codepostal *</label><br>
<input type="text" name="codepostal" value="' . $modif['codepostal'] . '"> <br>';
echo '<label for="adresse">adresse *</label><br>
<textarea name="adresse">' . $modif['adresse'] . '</textarea> <br>';
echo '<label for="date_de_naissance">Date de naissance</label><br>
<input type="date" name="date_de_naissance" value="' . $modif['date_de_naissance'] . '"><br>';
echo '<label for="sexe">sexe</label><br>
<input type="radio" name="sexe" class="sexe" value="m" checked>Homme
<input type="radio" name="sexe" classe="sexe" value="f">Femme<br>';
echo '<label for="description">description *</label><br>
<textarea name="description">' . $modif['description'] . '</textarea> <br>';
echo '<input type="submit" name="valider_modif" value="Modifier"> <br>';
}
if (isset($_POST['valider_modif'])){
echo "TEST";
}
}
?>
答案 0 :(得分:0)
您有2个表单,而您没有使用</form>
答案 1 :(得分:0)
您的第二次if
检查位于另一位$_POST['modifier']
内,因此只有在设置了$_POST['valider_modif']
和modifier
时才会运行。但是你的第二个表单不会在任何地方发送<input type="hidden" name="modifier" value="1" />
。
您可以在第二种形式中添加隐藏字段:
if
或者,如果您不想再次显示第二个表单,请将第二个$_POST
移到另一个表单之外。
此外,您不应直接在SQL查询中使用{{1}}值来保护SQL注入安全。应该使用类似mysqli_real_escape_string
的函数来首先转义值。
答案 2 :(得分:0)
花了很长时间来完成你的代码。好的。第一件事。尽量不要回复那么多html标记。它只会让你编码世界上最笨重的代码。从我收集的内容中,单击第一个按钮时会出现“修改器”按钮。如果你想看到TEST消息,你需要做的是将它从if语句中取出,因为Buttons就像一个异或门。设置另一个取消另一个