Undefined variable après un formulaire
Bonjour je développez web avec php
lorsque je fait une insertion des champs se ajouté et d'autre non
code php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <?php
// connexion à la base de données
require_once('Conextion/connect.php');
// -------------------------
// 1/ récupération des données du formulaire
$id_eleve1 = (isset($_POST['id_eleve1']))? $_POST['id_eleve1'] : '';
$nom_etudaint1 = (isset($_POST['nom_etudaint1']))? $_POST['nom_etudaint1'] : '';
$prenom_etudiant1 = (isset($_POST['prenom_etudiant1']))? $_POST['prenom_etudiant1'] : '';
$numero_telephone1 = (isset($_POST['numero_telephone1']))? $_POST['numero_telephone1'] : '';
$date_naissance1 = (isset($_POST['date_naissance1']))? $_POST['date_naissance1'] : '';
$lieu_naissance1 = (isset($_POST['lieu_naissance1']))? $_POST['lieu_naissance1'] : '';
$cin1 = (isset($_POST['cin1']))? $_POST['cin1'] : '';
$classe = (isset($_POST['classe']))? $_POST['classe'] : '';
// -------------------------
// 2/ Gestion des erreurs
$valid = 0;
// (ici, tous les champs sont obligatoires)
if( empty($id_eleve1)
OR empty($nom_etudaint1)
OR empty($prenom_etudiant1)
OR empty($date_naissance1)
OR empty($lieu_naissance1)
OR empty($numero_telephone1)
OR empty($cin1))
{
$valid = 2;
echo ' <a href="javascript:history.go(-1)"><h1 align="center"><font color="red">Attention, reste des champs vide !</font></h1></a>';
}
// N.B. on peut faire ICI d'autres tests d'erreurs :
// validité des données (ex. : numéro de téléphone, email,.......)
// pas d'erreur ?
if($valid != 2) {
$valid = 1;
}
// -------------------------
// 3/ Traitement si OK : Aucun champ n'est vide, on peut enregistrer dans la table
if($valid == 1)
{
// ---------------
// on PROTEGE les données contre les INJECTIONS SQL
$id_eleve1 = mysql_real_escape_string($id_eleve1);
$nom_etudaint1 = mysql_real_escape_string($nom_etudaint1);
$prenom_etudiant1 = mysql_real_escape_string($prenom_etudiant1);
$numero_telephone1 = mysql_real_escape_string($numero_telephone1);
$date_naissance1 = mysql_real_escape_string($date_naissance1);
$lieu_naissance1 = mysql_real_escape_string($lieu_naissance1);
$cin1 = mysql_real_escape_string($cin1);
$classe = mysql_real_escape_string($classe);
// ---------------
// on écrit la requête sql
mysql_select_db($database_connect, $connect);
$sql = "INSERT INTO `eleve`
(id_eleve,nom,prenom,num_telephone,date_naissance,lieu_naissance,cin,code_classe)
VALUES('$id_eleve1','$nom1','$prenom1','$num_telephone1','$date_naissance1','$lieu_naissance1','$cin1','$classe')";
// ---------------
// on insère les informations du formulaire dans la table
mysql_query($sql) or die('Erreur SQL !'.$sql.'<br>'.mysql_error());
}
// ---------------
mysql_close(); // on ferme la connexion
// ---------------
// Redirection (?)
header('location:ajoute_etudiant.php');
?> |
code html :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ajouté eleve</title>
<style type="text/css">
<!--
.Style2 {
font-size: 12px;
font-family: "Times New Roman", Times, serif;
}
-->
</style>
</head>
<body>
<h3> ajouté un nouveaux éléve </h3>
<?php $base=mysql_connect('localhost','root','');
mysql_select_db('newstyle',$base);
?>
<form method="post" action="ajout.php" >
<table width="476" height="356" border="1">
<tr>
<th width="221" scope="row">Numero d'inscription</th>
<td width="239"><input name="id_eleve1" type="text" maxlength="10" class="backgroundTextField"/></td>
</tr>
<tr>
<th scope="row">Nom étudaint(e)</th>
<td><input name="nom_etudaint1" type="text" maxlength="10" class="backgroundTextField"/></td>
</tr>
<tr>
<th scope="row">Prénom étudiant(e)</th>
<td><input name="prenom_etudiant1" type="text" maxlength="10" class="backgroundTextField"/></td>
</tr>
<tr>
<th scope="row">date naissance</th>
<td><input name="date_naissance1" type="text" maxlength="10" class="backgroundTextField"/></td>
</tr>
<tr>
<th scope="row"><span class="Style2"></span>lieu naissance</th>
<td><input name="lieu_naissance1" type="text" maxlength="10" class="backgroundTextField"/></td>
</tr>
<tr>
<th scope="row">cin</th>
<td><input name="cin1" type="text" maxlength="10" class="backgroundTextField"/></td>
</tr>
<tr>
<th scope="row">numero telephone </th>
<td><input name="numero_telephone1" type="text" maxlength="10" class="backgroundTextField"/></td>
</tr>
<tr>
<th scope="row">Section </th>
<td><input name="classe" type="text" maxlength="10" class="backgroundTextField"/></td>
</tr>
</table>
<label>
<input type="submit" name="button" id="button" value="Envoyer" />
</label>
</form>
</body>
</html> |
je verifier lorceque je suis dans phpmyadmin ce me affiche aucun erreur un fichier attaché va vous monttre
ca veux pas joindre image
alors il ne enregister pas nom, prenom numero_telephone,date_naissance
voila erreur:
Citation:
! ) Notice: Undefined variable: nom1 in C:\wamp\www\NS\ajout.php on line 58
Call Stack
# Time Memory Function Location
1 0.0000 152472 {main}( ) ..\ajout.php:0
( ! ) Notice: Undefined variable: prenom1 in C:\wamp\www\NS\ajout.php on line 58
Call Stack
# Time Memory Function Location
1 0.0000 152472 {main}( ) ..\ajout.php:0
( ! ) Notice: Undefined variable: num_telephone1 in C:\wamp\www\NS\ajout.php on line 58
Call Stack
# Time Memory Function Location
1 0.0000 152472 {main}( ) ..\ajout.php:0