从帖子表单中获取数据

I don't understand why I can't use my last form in this code. I generated a form using a SELECT list to select the member that I want to update and it works, but I don't know why I can't use datas from this form. Actually, I can't even echo something (see the echo "TEST"; at the end, nothing happens when I submit the form).

<?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";



        }
    }
?>

Your second if check is inside the other one, so it will only run when both $_POST['modifier'] and $_POST['valider_modif'] are set. But you second form does not send modifier anywhere.

You could add a hidden field to your second form:

<input type="hidden" name="modifier" value="1" />

Or if you don't want to show the second form again, move the second if outside the other.

Also, you should not use $_POST values in SQL queries directly to be safe from SQL injection. A function like mysqli_real_escape_string should be used to escape the value first.

You have 2 forms and you are not closing the 2nd with </form>

Took me a long time to go through your code. Okay. First thing. Try not to echo so much html markup. It just makes you code the clunkiest in the world. From what I gathered, the Modifier button comes up when you click on the first button. What you need to do if you want to see the TEST message is to take it out of the if statement because the Buttons are like an XOR gate. Setting the other unsets the other