PHP file is:
<?php
require_once("connexion.php");
$nom = $prenom = $adresse = $age = "";
if ($_SERVER["REQUEST_METHOD"] == "GET") {
$nom = $_GET["nom"];
$prenom = $_GET["prenom"];
$adresse = $_GET["adresse"];
$age = $_GET["age"];
}
$sql = "INSERT INTO etudiant (nom, prenom, adresse, age) VALUES (?, ?, ?, ?)";
$stmt = mysqli_prepare($connexion, $sql);
mysqli_stmt_bind_param($stmt, "ssss", $param_nom, $param_prenom, $param_adresse, $param_age);
$param_nom = $nom;
$param_prenom = $prenom;
$param_adresse = $adresse;
$param_age = $age;
if (!empty($param_nom) && !empty($param_prenom) && !empty($param_adresse) && !empty($param_age)) {
$stmt -> execute();
}
mysqli_close($connexion);
?>
My HTML :
<html>
<style>
</style>
<body>
<h2> Ajouter un nouveau étudiant</h2>
<p>Merci de remplir tous les champs afin d'ajouter un nouveau étudiant</p>
<form method="GET" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="">Nom :</label>
<input type="text" name="nom" placeholder=" Nom *" value="<?php echo $nom; ?>">
</br></br>
<label for="">Prénom :</label>
<input type="text" name="prenom" placeholder=" Prénom *" value="<?php echo $prenom; ?>">
</br></br>
<label for="">Adresse :</label>
<input type="text" name="adresse" placeholder=" Adresse *" value="<?php echo $adresse; ?>">
</br></br>
<label for="">Age :</label>
<input type="numeric" name="age" placeholder=" Age *" value="<?php echo $age; ?>">
</br></br>
<input type="submit" name="envoyer" value="Submit" onclick="self.location.href='affichage_etudiant.php'">
<input type="reset" name="reset" value="Annuler">
</form>
</body>
</html>
I'm working on php forms using the GET method an I got this error, please help !
When I complete my form and I send my form, result is:
Notice: Undefined index in line 9, 10, 11, 12.
I used the GET method because they asked me to do with like that, Grr.