IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PHP & Base de données Discussion :

verification donnees formulaire php [MySQL]


Sujet :

PHP & Base de données

  1. #1
    Membre confirmé
    Inscrit en
    Juillet 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 107
    Par défaut verification donnees formulaire php
    Bonjour,
    POur mon formulaire d'authentification, j'aimerai effectuer plusieurs contrôles avant la validation comme la vérification de l'existence ou non de l'email dans la base, la vérification de le concordance des deux mots de passe tapés, et puis le contrôle dans les champs, l'email, la longueur du nom, la longueur du prénom... Mais le problème est que je ne sais pas comment organiser tout ça, je n'ai qu'une partie des contrôles qui se font.
    Est-ce que vous pouvez m'aider ou m'orienter ?
    Merci d'avance


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
     
       <?php
     
        // on teste si le visiteur a soumis le formulaire
        if (isset($_POST['inscription']) && $_POST['inscription'] == 'I create my account') { 
     
           // on teste l'existence de nos variables. On teste également si elles ne sont pas vides
     
           if ((isset($_POST['email']) && !empty($_POST['email'])) 
    	   && (isset($_POST['password']) && !empty($_POST['password'])) 
    	   && (isset($_POST['titre']) && !empty($_POST['titre'])) 
    	   && (isset($_POST['prenom']) && !empty($_POST['prenom']) && strlen($_POST['prenom'])>4) 
    	   && (isset($_POST['nom']) && !empty($_POST['nom']) && strlen($_POST['prenom'])>4) 
    	   && (isset($_POST['pass_confirm']) && !empty($_POST['pass_confirm']))) { 
     
              // on teste les deux mots de passe
              if(!empty($_POST) && strlen($_POST['prenom'])<4){
                 $error_prenom = ' Votre prenom doit comporter au minimun 4 caracteres !';
        	  }
     
     
    		  if(!empty($_POST) && strlen($_POST['nom'])<4){
                 $error_nom = ' Votre nom doit comporter au minimun 4 caracteres !';
              }
    		  if(!empty($_POST) && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
                 $error_email = ' Votre Email n\'est pas valide !';
              } 
    		  if(!empty($_POST) && strlen($_POST['password'])<6){
                 $error_password = ' Votre password doit comporter au minimun 6 caracteres !';
              }
     
     
    		  if ($_POST['password'] != $_POST['pass_confirm']) { 
                 $erreur = 'Les 2 mots de passe sont différents.'; 
              } 
     
     
     
     
     
              else { 
     
                 $base = mysql_connect ('localhost', 'root', ''); 
              mysql_select_db ('membres', $base); 
     
                 // on recherche si ce login est déjà utilisé par un autre membre
                 $sql = 'SELECT count(*) FROM membre WHERE email="'.mysql_escape_string($_POST['email']).'"'; 
                 $req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error()); 
                 $data = mysql_fetch_array($req); 
     
    	 // si cet email n'est pas déjà présent dans la table, on peut l'enregistrer $data = 0
                 if ($data[0] == 0) { 
                    $sql = 'INSERT INTO membre VALUES("",
    				"'.mysql_escape_string($_POST['email']).'", 
    				"'.mysql_escape_string(md5($_POST['password'])).'",
    				"'.mysql_escape_string($_POST['titre']).'",
    				"'.mysql_escape_string($_POST['prenom']).'",
    				"'.mysql_escape_string($_POST['nom']).'",
    				"")'; 
     
                    mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error()); 
     
    	 			// et on commence la session qui s'appelle email
                    session_start(); 
                    $_SESSION['email'] = $_POST['email']; 
                    header('Location: inscription2.php'); 
                    exit(); 
                 } 
                 else { 
                    $erreur = 'Un membre possède déjà ce login.'; 
                 } 
              } 
           } 
           else { 
              $erreur = 'Au moins un des champs est vide.'; 
           }  
        } 
        ?>
        <html>
        <head>
        <title>Inscription</title>
     
        </head>
     
        <body>
     
     
     
    	<div id="contour_formulaire">
     
            <form action="inscription.php" method="post">
    		<fieldset style="border-color:#73aad2;border-size:2px;" width="625">  
    		<legend class="titre_labelaut">Open your personal Interchim web account &amp; get benefit of many advantages   :</legend>
     
     
     
        <br/>              
    		<table width="628" border="0" cellpadding="0" cellspacing="0" >
     
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
     
    		  		  <tr>
        	<td width="132"> <label for="titre" class="TexteLogin">Title : </label></td>
    		<td width="59" class="TexteCheck"><label><input name="titre" type="radio"  value="Mr" checked="checked" />
    		  Mr &nbsp;&nbsp;&nbsp;</label></td>
      		<td width="80" class="TexteCheck"><label><input name="titre" type="radio" value="Mme" />Mme &nbsp;&nbsp;&nbsp;</label></td>
      		<td colspan="2" class="TexteCheck"><label><input name="titre" type="radio" value="Mlle" />
                Mlle</label></td>
      		<td width="280" class="error2"></td>
      		</tr>	  
     
     
      		<tr>
        	<td width="132"> <label for="prenom" class="TexteLogin">First Name : </label></td>
    		<td colspan="3">
    		<input type="text" name="prenom" class="loginRemplissage" value="<?php if (isset($_POST['prenom'])) echo htmlentities(trim($_POST['prenom'])); ?>"> 
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if(isset($error_prenom)){ echo $error_prenom; } ?>
    		</td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="nom" class="TexteLogin">Family Name  : </label></td>
    		<td colspan="3">
    		<input type="text" name="nom" class="loginRemplissage" value="<?php if (isset($_POST['nom'])) echo htmlentities(trim($_POST['nom'])); ?>">		  
    		<span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if(isset($error_nom)){ echo $error_nom; } ?>
    		</td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error2"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="email" class="TexteLogin">E-mail : </label></td>
    		<td colspan="3">
    		<input type="text" name="email" class="loginRemplissage" value="<?php if (isset($_POST['email'])) echo htmlentities(trim($_POST['email'])); ?>">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if(isset($error_email)){ echo $error_email; } ?>
    		</td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">My password : </label></td>
    		<td colspan="3">
    		<input type="password" name="password" class="loginRemplissage" value="<?php if (isset($_POST['password'])) echo htmlentities(trim($_POST['password'])); ?>">
    		  <span class="error">*</span></td> 
      		<td colspan="2" class="error2"><?php if(isset($error_password)){ echo $error_password; } ?>
    		</td>
      		</tr>
    		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">Confirm password : </label></td>
    		<td colspan="3">
    		<input type="password" name="pass_confirm" class="loginRemplissage" value="<?php if (isset($_POST['pass_confirm'])) echo htmlentities(trim($_POST['pass_confirm'])); ?>">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if(isset($error_password)){ echo $error_password; } ?>
    		</td>
      		</tr>
     
     
      		<tr>
      		  <td>&nbsp;</td>
      		  <td colspan="5"><?php if (isset($erreur)) echo '<br />',$erreur;  ?></td>
    		  </tr>
      		<tr>
      		  <td height="43"></td>
      		  <td colspan="5"> <input type="submit" name="inscription" class="AlignementCreateAccount" value="I create my account"/></td>
    		  </tr>
      		<tr>
      		  <td height="19">&nbsp;</td>
      		  <td colspan="5"><span class="error">*</span> <span class="error">Must be mandatory filled </span></td>
    		  </tr>
      		</table>
     
     
              </fieldset>     
      </form><br/>		   
    </div>
     
     
     
        </body>
        </html>

  2. #2
    Membre émérite
    Inscrit en
    Juillet 2003
    Messages
    625
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 625
    Par défaut
    Bonjour,

    tu peux faire un tableau d'erreur par exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
     
    if ( !empty($_POST) ) {
     
    $tabError = array();
     
    if ( strlen($_POST['prenom'])<4) {
    $tabError[] = ' Votre prenom doit comporter au minimun 4 caracteres !';
    }
    etc ...
     
    if ( empty($tabError) ) {
     
    //traitement si pas d'erreur
     
    }
    else {
     
    // affichage erreur
     
    foreach ( $tabError as $error ) {
    echo $error,'<br />';
    }
     
    }
     
     
     
    }

  3. #3
    Membre confirmé
    Inscrit en
    Juillet 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 107
    Par défaut
    Merci Syl2095,
    J'essaye de mettre ta proposition en place !

  4. #4
    Membre confirmé
    Inscrit en
    Juillet 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 107
    Par défaut
    Bonjour,
    J'ai essayé de mettre mes erreurs dans un tableau, le script marche très bien, merci beaucoup pour votre aide. Cependant, j'essaye dans une autre approche de mettre mes erreurs à côté du champ, donc il faudrait que je fasse un tableau indicé, ce que j'ai commencé à mettre en place... je suis bloquée dans la syntaxe, je ne sais pas comment l'intégrer.... je fais encore appel à vous si vous voulez bien.
    merci

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
     
        <?php
     
           // Initialisation des variables -isset détermine si variable est définie et différente de null
    		$email	= isset($_POST['email']) ? $_POST['email'] : '' ;
    		$password = isset($_POST['password']) ? $_POST['password'] : '' ;
    		$titre	= isset($_POST['titre']) ? $_POST['titre'] : '' ;
    		$prenom	= isset($_POST['prenom']) ? $_POST['prenom'] : '' ;
    		$nom	= isset($_POST['nom']) ? $_POST['nom'] : '' ;
    		$pass_confirm	= isset($_POST['pass_confirm']) ? $_POST['pass_confirm'] : '' ;
     
    		$erreur =  isset($erreur) ? $erreur : '' ;   
    		{ 
     
    	   	  // Test des champs du formulaire
    		  if (isset($_POST['inscription']) && $_POST['inscription'] == 'I create my account') {
     
     
    		  // Construction du tableau d'erreurs
    		  $erreur = array(0 => 'prenom',
    		                  1 => 'nom',
    						  2 => 'email',
    						  3 => 'password',
    						  4 => 'password2');
     
              // on teste les deux mots de passe
              if(!empty($_POST) && strlen($_POST['prenom'])<4){
                 $erreur['prenom'] = ' Votre prenom doit comporter au minimun 4 caracteres !';
        	  }
     
    		  if(!empty($_POST) && strlen($_POST['nom'])<4){
                 $erreur['nom'] = ' Votre nom doit comporter au minimun 4 caracteres !';
              }
     
    		  if(!empty($_POST) && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
                 $erreur['email'] = ' Votre Email n\'est pas valide !';
              } 
    		  if(!empty($_POST) && strlen($_POST['password'])<6){
                 $erreur['password'] = ' Votre password doit comporter au minimun 6 caracteres !';
              }
     
    		  if ($_POST['password'] != $_POST['pass_confirm']) { 
                 $erreur['password2'] = 'Les 2 mots de passe sont différents.'; 
              } 
     
     
    		  // On enregistre dans la variable '$nb_erreur', le nombre d'erreurs
    		  $nb_erreur = count($erreur);
     
    		  // Si pas d'erreur
    		  if (!$nb_erreur){
     
                 $base = mysql_connect ('localhost', 'root', ''); 
              mysql_select_db ('membres', $base); 
     
                 // on recherche si ce login est déjà utilisé par un autre membre
                 $sql = 'SELECT count(*) FROM membre WHERE email="'.mysql_escape_string($_POST['email']).'"'; 
                 $req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error()); 
                 $data = mysql_fetch_array($req); 
     
    	 // si cet email n'est pas déjà présent dans la table, on peut l'enregistrer $data = 0
                 if ($data[0] == 0) { 
                    $sql = 'INSERT INTO membre VALUES("",
    				"'.mysql_escape_string($_POST['email']).'", 
    				"'.mysql_escape_string(md5($_POST['password'])).'",
    				"'.mysql_escape_string($_POST['titre']).'",
    				"'.mysql_escape_string($_POST['prenom']).'",
    				"'.mysql_escape_string($_POST['nom']).'",
    				"")'; 
     
                    mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error()); 
     
    	 			// et on commence la session qui s'appelle email
                    session_start(); 
                    $_SESSION['email'] = $_POST['email']; 
                    header('Location: inscription2.php'); 
                    exit(); 
                 } 
                 else { 
                    $erreur2 = 'Un membre possède déjà ce login.'; 
                 } 
              } 
           } 
           else { 
              $erreur2 = 'Au moins un des champs est vide.'; 
           }  
        }  
        ?>
        <html>
        <head>
        <title>Inscription</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
     
        </head>
     
        <body>
     
     
     
    	<div id="contour_formulaire">
     
            <form action="inscriptionTest3.php" method="post">
    		<fieldset style="border-color:#73aad2;border-size:2px;" width="625">  
     
     
     
     
     
     
        <br/>
     
     
     
     
     
     
     
     
     
    		<table width="628" border="0" cellpadding="0" cellspacing="0" >
     
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
     
    		  		  <tr>
        	<td width="132"> <label for="titre" class="TexteLogin">Title : </label></td>
    		<td width="59" class="TexteCheck"><label><input name="titre" type="radio"  value="Mr" checked="checked" />
    		  Mr &nbsp;&nbsp;&nbsp;</label></td>
      		<td width="80" class="TexteCheck"><label><input name="titre" type="radio" value="Mme" />Mme &nbsp;&nbsp;&nbsp;</label></td>
      		<td colspan="2" class="TexteCheck"><label><input name="titre" type="radio" value="Mlle" />
                Mlle</label></td>
      		<td width="280" class="error2"></td>
      		</tr>	  
     
     
      		<tr>
        	<td width="132"> <label for="prenom" class="TexteLogin">First Name : </label></td>
    		<td colspan="3">
    		<input type="text" name="prenom" class="loginRemplissage" value="<?php if (isset($_POST['prenom'])) echo htmlentities(trim($_POST['prenom'])); ?>"> 
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if(isset($erreur)){ echo $erreur['prenom']; } ?></td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="nom" class="TexteLogin">Family Name  : </label></td>
    		<td colspan="3">
    		<input type="text" name="nom" class="loginRemplissage" value="<?php if (isset($_POST['nom'])) echo htmlentities(trim($_POST['nom'])); ?>">		  
    		<span class="error">*</span></td>
      		<td colspan="2" class="error2">&nbsp;</td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error2"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="email" class="TexteLogin">E-mail : </label></td>
    		<td colspan="3">
    		<input type="text" name="email" class="loginRemplissage" value="<?php if (isset($_POST['email'])) echo htmlentities(trim($_POST['email'])); ?>">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2">&nbsp;</td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">My password : </label></td>
    		<td colspan="3">
    		<input type="password" name="password" class="loginRemplissage" value="<?php if (isset($_POST['password'])) echo htmlentities(trim($_POST['password'])); ?>">
    		  <span class="error">*</span></td> 
      		<td colspan="2" class="error2">&nbsp;</td>
      		</tr>
    		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">Confirm password : </label></td>
    		<td colspan="3">
    		<input type="password" name="pass_confirm" class="loginRemplissage" value="<?php if (isset($_POST['pass_confirm'])) echo htmlentities(trim($_POST['pass_confirm'])); ?>">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2">&nbsp;</td>
      		</tr>
     
     
      		<tr>
      		  <td>&nbsp;</td>
      		  <td colspan="5"><?php if (isset($erreur2)) echo '<br />',$erreur2;  ?></td>
    		  </tr>
      		<tr>
      		  <td height="43"></td>
      		  <td colspan="5"> <input type="submit" name="inscription" class="AlignementCreateAccount" value="I create my account"/></td>
    		  </tr>
      		<tr>
      		  <td height="19">&nbsp;</td>
      		  <td colspan="5"><span class="error">*</span> <span class="error">Must be mandatory filled </span></td>
    		  </tr>
      		</table>
     
    			<p class="TexteFormulaireNombreProduits" id="contour_formulaire"><strong>Confidentiality : </strong><br />
      The information you provide to us is strictly confidential and will under no circumstances be disclose or transfer to another person. Our site si only for professionals. </p> 	   
     
              </fieldset>     
      </form><br/>		   
    </div>
     
     
     
        </body>
        </html>

  5. #5
    Membre Expert
    Avatar de ska_root
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2005
    Messages
    1 203
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Service public

    Informations forums :
    Inscription : Août 2005
    Messages : 1 203
    Par défaut
    Bonjour,

    tu mets des indices numériques, il suffirait de créer des indices explicites à la place...

    exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    <?php
    // on initialise le tableau des erreurs
    $erreurs= array(
       "password" => array("msg" => ""),
       "nom" => array("msg" => ""),
       //etc....
    );
    $error_exist= false;
     
    if(isset($_POST["inscription"])) {
    ...
    ...
       $pass_ko=(strlen($password) < 6);
       if($pass_ko) {
           $erreurs["password"]["msg"].="Votre password doit comporter au minimun 6 caracteres !<br/>";
           $error_exist= true;
       }
       if($password != $pass_confirm) {
          $erreurs["password"]["msg"].= "Les 2 mots de passe sont différents.<br/>";
          $error_exist= true;
       }
     
     
       if(!$error_exist) {
          // requete sql
       }
    ...
    ...
    }
    ...
    ...
    <tr>
       <td width="132"> <label for="password" class="TexteLogin">My password : </label></td>
    		<td colspan="3">
    		<input type="password" name="password" class="loginRemplissage" value="<?php if (isset($_POST['password'])) echo htmlentities(trim($_POST['password'])); ?>">
    		  <span class="error">*</span></td> 
      		<td colspan="2" class="error2"><?php echo $erreurs['password']['msg']; ?></td>
      		</tr>
    ...
    ...
    ?>

    tu peux aussi ajouter un contrôle javascript qui le fera très bien. mais bon, c'est pas la question...


  6. #6
    Membre émérite
    Inscrit en
    Juillet 2003
    Messages
    625
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 625
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $tabError['prenom'] = ' Votre prenom doit comporter au minimun 4 caracteres !';
    Ensuite, à côté du champs en question :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    if ( !empty($tabError['prenom']) ) echo $tabError['prenom'];

  7. #7
    Membre confirmé
    Inscrit en
    Juillet 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 107
    Par défaut
    merci à tous les deux pour vos réponses rapides, ça m'aide beaucoup.

    J'ai essayé vos deux solutions, avec la tienne, syl 2095, ça marche sur mes premières erreurs mais je n'ai plus de vérification de l'existence ou pas de l'email dans la base. erreurs fonctionne mais plus erreur2 en fait.

    Je te mets ce que j'ai fait :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
     
        <?php
     
        // on teste si le visiteur a soumis le formulaire
     
     
           // Initialisation des variables -isset détermine si variable est définie et différente de null
    		$email	= isset($_POST['email']) ? $_POST['email'] : '' ;
    		$password = isset($_POST['password']) ? $_POST['password'] : '' ;
    		$titre	= isset($_POST['titre']) ? $_POST['titre'] : '' ;
    		$prenom	= isset($_POST['prenom']) ? $_POST['prenom'] : '' ;
    		$nom	= isset($_POST['nom']) ? $_POST['nom'] : '' ;
    		$pass_confirm	= isset($_POST['pass_confirm']) ? $_POST['pass_confirm'] : '' ;
     
    		$erreur =  isset($erreur) ? $erreur : '' ;   
    		{ 
     
    	   	  // Test des champs du formulaire
     
    		  if (isset($_POST['inscription']) && $_POST['inscription'] == 'I create my account') {
     
     
    		  // Construction du tableau d'erreurs
    		  $erreur = array();
     
              // on teste les deux mots de passe
              if(!empty($_POST) && strlen($_POST['prenom'])<4){
                 $erreur['prenom'] = ' Votre prenom doit comporter au minimun 4 caracteres !';
        	  }
     
    		  if(!empty($_POST) && strlen($_POST['nom'])<4){
                 $erreur['nom'] = ' Votre nom doit comporter au minimun 4 caracteres !';
              }
     
    		  if(!empty($_POST) && !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
                 $erreur['email'] = ' Votre Email n\'est pas valide !';
              } 
    		  if(!empty($_POST) && strlen($_POST['password'])<6){
                 $erreur['password'] = ' Votre password doit comporter au minimun 6 caracteres !';
              }
     
    		  if ($_POST['password'] != $_POST['pass_confirm']) { 
                 $erreur['password2'] = 'Les 2 mots de passe sont différents.'; 
              } 
     
     
    		  // On enregistre dans la variable '$nb_erreur', le nombre d'erreurs
    		  $nb_erreur = count($erreur);
     
    		  // Si pas d'erreur
    		  if (!$nb_erreur){
     
                 $base = mysql_connect ('localhost', 'root', ''); 
              mysql_select_db ('membres', $base); 
     
                 // on recherche si ce login est déjà utilisé par un autre membre
                 $sql = 'SELECT count(*) FROM membre WHERE email="'.mysql_escape_string($_POST['email']).'"'; 
                 $req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error()); 
                 $data = mysql_fetch_array($req); 
     
    	 // si cet email n'est pas déjà présent dans la table, on peut l'enregistrer $data = 0
                 if ($data[0] == 0) { 
                    $sql = 'INSERT INTO membre VALUES("",
    				"'.mysql_escape_string($_POST['email']).'", 
    				"'.mysql_escape_string(md5($_POST['password'])).'",
    				"'.mysql_escape_string($_POST['titre']).'",
    				"'.mysql_escape_string($_POST['prenom']).'",
    				"'.mysql_escape_string($_POST['nom']).'",
    				"")'; 
     
                    mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error()); 
     
    	 			// et on commence la session qui s'appelle email
                    session_start(); 
                    $_SESSION['email'] = $_POST['email']; 
                    header('Location: inscription2.php'); 
                    exit(); 
                 } 
                 else { 
                    $erreur2 = 'Un membre possède déjà ce login.'; 
                 } 
              } 
           } 
           else { 
              $erreur2 = 'Au moins un des champs est vide.'; 
           }  
        }  
        ?>
        <html>
        <head>
        <title>Inscription</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link rel="stylesheet" href="StylesFormulaireAuthentification.css" type="text/css" charset="utf-8"/>
        </head>
     
        <body>
     
     
     
    	<div id="contour_formulaire">
     
            <form action="inscription3.php" method="post">
    		<fieldset style="border-color:#73aad2;border-size:2px;" width="625">  
    		<legend class="titre_labelaut"></legend>
     
    <br/>
     
     
    	<?php 
    	// Si il y a une/des erreur(s)
    	if($erreur2){
     
    		// On affiche sous forme de liste chaque texte d'erreur stocké dans notre tableau '$erreur'
    		echo "<h3>Errreur(s)</h3>";
    		echo "<ul>";
     
    		foreach ($erreur2 as $errreurTexte) {
    			echo "<li>".$errreurTexte."</li>" ;
    		}
    		echo "</ul>";	
    	}
    ?>
     
     
     
     
     
     
    		<table width="628" border="0" cellpadding="0" cellspacing="0" >
     
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
     
    		  		  <tr>
        	<td width="132"> <label for="titre" class="TexteLogin">Title : </label></td>
    		<td width="59" class="TexteCheck"><label><input name="titre" type="radio"  value="Mr" checked="checked" />
    		  Mr &nbsp;&nbsp;&nbsp;</label></td>
      		<td width="80" class="TexteCheck"><label><input name="titre" type="radio" value="Mme" />Mme &nbsp;&nbsp;&nbsp;</label></td>
      		<td colspan="2" class="TexteCheck"><label><input name="titre" type="radio" value="Mlle" />
                Mlle</label></td>
      		<td width="280" class="error2"></td>
      		</tr>	  
     
     
      		<tr>
        	<td width="132"> <label for="prenom" class="TexteLogin">First Name : </label></td>
    		<td colspan="3">
    		<input type="text" name="prenom" class="loginRemplissage" value="<?php if (isset($_POST['prenom'])) echo htmlentities(trim($_POST['prenom'])); ?>"> 
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if ( !empty($erreur['prenom']) ) echo $erreur['prenom']; ?></td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="nom" class="TexteLogin">Family Name  : </label></td>
    		<td colspan="3">
    		<input type="text" name="nom" class="loginRemplissage" value="<?php if (isset($_POST['nom'])) echo htmlentities(trim($_POST['nom'])); ?>">		  
    		<span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if ( !empty($erreur['nom']) ) echo $erreur['nom']; ?></td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error2"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="email" class="TexteLogin">E-mail : </label></td>
    		<td colspan="3">
    		<input type="text" name="email" class="loginRemplissage" value="<?php if (isset($_POST['email'])) echo htmlentities(trim($_POST['email'])); ?>">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if ( !empty($erreur['email']) ) echo $erreur['email']; ?></td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">My password : </label></td>
    		<td colspan="3">
    		<input type="password" name="password" class="loginRemplissage" value="<?php if (isset($_POST['password'])) echo htmlentities(trim($_POST['password'])); ?>">
    		  <span class="error">*</span></td> 
      		<td colspan="2" class="error2"><?php if ( !empty($erreur['password']) ) echo $erreur['password']; ?></td>
      		</tr>
    		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">Confirm password : </label></td>
    		<td colspan="3">
    		<input type="password" name="pass_confirm" class="loginRemplissage" value="<?php if (isset($_POST['pass_confirm'])) echo htmlentities(trim($_POST['pass_confirm'])); ?>">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2">&nbsp;</td>
      		</tr>
     
     
      		<tr>
      		  <td>&nbsp;</td>
      		  <td colspan="5"><?php if (isset($erreur2)) echo '<br />',$erreur2;  ?></td>
    		  </tr>
      		<tr>
      		  <td height="43"></td>
      		  <td colspan="5"> <input type="submit" name="inscription" class="AlignementCreateAccount" value="I create my account"/></td>
    		  </tr>
      		<tr>
      		  <td height="19">&nbsp;</td>
      		  <td colspan="5"><span class="error">*</span> <span class="error">Must be mandatory filled </span></td>
    		  </tr>
      		</table>
     
    			<p class="TexteFormulaireNombreProduits" id="contour_formulaire">&nbsp;</p> 	   
     
              </fieldset>     
      </form><br/>		   
    </div>
     
     
     
        </body>
        </html>

  8. #8
    Membre confirmé
    Inscrit en
    Juillet 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 107
    Par défaut
    Et le tableau indicé pour ska_root pour lequel j'ai des erreurs notices, variables non définies sinon c'est une méthode qui me conviendrait.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
     
     
        <?php
     
        // on teste si le visiteur a soumis le formulaire
     
     
           // Initialisation des variables -isset détermine si variable est définie et différente de null
    		$email	= isset($_POST['email']) ? $_POST['email'] : '' ;
    		$password = isset($_POST['password']) ? $_POST['password'] : '' ;
    		$titre	= isset($_POST['titre']) ? $_POST['titre'] : '' ;
    		$prenom	= isset($_POST['prenom']) ? $_POST['prenom'] : '' ;
    		$nom	= isset($_POST['nom']) ? $_POST['nom'] : '' ;
    		$pass_confirm	= isset($_POST['pass_confirm']) ? $_POST['pass_confirm'] : '' ;
     
     
     
     
     
    		{ 
     
    	   	  // Test des champs du formulaire
     
    		  if (isset($_POST['inscription']) && $_POST['inscription'] == 'I create my account') {
     
     
    		  // Construction du tableau d'erreurs
    		  	$erreurs= array(
       				"prenom" => array("msg" => ""),
       				"nom" => array("msg" => ""),
    				"email" => array("msg" => ""),
    				"password" => array("msg" => ""),
    			);
     
    			$error_exist= false;
     
    		  if(isset($_POST["inscription"])) {
     
     
            // on teste les deux mots de passe
            $pass_ko=(strlen($password) < 6);
       		if($pass_ko) {
           	$erreurs["password"]["msg"].="Votre password doit comporter au minimun 6 caracteres !<br/>";
           	$error_exist= true;
       		}
     
    		if($password != $pass_confirm) {
            $erreurs["password"]["msg"].= "Les 2 mots de passe sont différents.<br/>";
          	$error_exist= true;
       		}
     
    		$nom_ko=(strlen($nom) < 4);
       		if($nom_ko) {
           	$erreurs["nom"]["msg"].="Votre nom doit comporter au minimun 4 caracteres !<br/>";
           	$error_exist= true;
       		}
     
    		$nom_ko=(strlen($prenom) < 4);
       		if($prenom_ko) {
           	$erreurs["prenom"]["msg"].="Votre prenom doit comporter au minimun 4 caracteres !<br/>";
           	$error_exist= true;
       		}
     
    		$email_ok=(filter_var($email, FILTER_VALIDATE_EMAIL));
       		if($email_ok) {
           	$erreurs["email"]["msg"].="Votre Email n\'est pas valide !<br/>";
           	$error_exist= true;
       		}
     
     
     
     
     
    		  if(!$error_exist) {
     
                 $base = mysql_connect ('localhost', 'root', ''); 
              mysql_select_db ('membres', $base); 
     
                 // on recherche si ce login est déjà utilisé par un autre membre
                 $sql = 'SELECT count(*) FROM membre WHERE email="'.mysql_escape_string($_POST['email']).'"'; 
                 $req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error()); 
                 $data = mysql_fetch_array($req); 
     
    	 // si cet email n'est pas déjà présent dans la table, on peut l'enregistrer $data = 0
                 if ($data[0] == 0) { 
                    $sql = 'INSERT INTO membre VALUES("",
    				"'.mysql_escape_string($_POST['email']).'", 
    				"'.mysql_escape_string(md5($_POST['password'])).'",
    				"'.mysql_escape_string($_POST['titre']).'",
    				"'.mysql_escape_string($_POST['prenom']).'",
    				"'.mysql_escape_string($_POST['nom']).'",
    				"")'; 
     
                    mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error()); 
     
    	 			// et on commence la session qui s'appelle email
                    session_start(); 
                    $_SESSION['email'] = $_POST['email']; 
                    header('Location: inscription2.php'); 
                    exit(); 
                 } 
                 else { 
                    $erreur2 = 'Un membre possède déjà ce login.'; 
                 } 
              } 
           } 
           else { 
              $erreur2 = 'Au moins un des champs est vide.'; 
           }  
        }    }
        ?>
        <html>
        <head>
        <title>Inscription</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link rel="stylesheet" href="StylesFormulaireAuthentification.css" type="text/css" charset="utf-8"/>
        </head>
     
        <body>
     
     
     
    	<div id="contour_formulaire">
     
            <form action="inscriptionTableauIndice.php" method="post">
    		<fieldset style="border-color:#73aad2;border-size:2px;" width="625">  
    		<legend class="titre_labelaut"></legend>
     
    <br/>
     
     
     
     
     
    		<table width="628" border="0" cellpadding="0" cellspacing="0" >
     
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
     
    		  		  <tr>
        	<td width="132"> <label for="titre" class="TexteLogin">Title : </label></td>
    		<td width="59" class="TexteCheck"><label><input name="titre" type="radio"  value="Mr" checked="checked" />
    		  Mr &nbsp;&nbsp;&nbsp;</label></td>
      		<td width="80" class="TexteCheck"><label><input name="titre" type="radio" value="Mme" />Mme &nbsp;&nbsp;&nbsp;</label></td>
      		<td colspan="2" class="TexteCheck"><label><input name="titre" type="radio" value="Mlle" />
                Mlle</label></td>
      		<td width="280" class="error2"></td>
      		</tr>	  
     
     
      		<tr>
        	<td width="132"> <label for="prenom" class="TexteLogin">First Name : </label></td>
    		<td colspan="3">
    		<input type="text" name="prenom" class="loginRemplissage" value="<?php if (isset($_POST['prenom'])) echo htmlentities(trim($_POST['prenom'])); ?>"> 
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php echo $erreurs['prenom']['msg']; ?></td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="nom" class="TexteLogin">Family Name  : </label></td>
    		<td colspan="3">
    		<input type="text" name="nom" class="loginRemplissage" value="<?php if (isset($_POST['nom'])) echo htmlentities(trim($_POST['nom'])); ?>">		  
    		<span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php echo $erreurs['nom']['msg']; ?></td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error2"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="email" class="TexteLogin">E-mail : </label></td>
    		<td colspan="3">
    		<input type="text" name="email" class="loginRemplissage" value="<?php if (isset($_POST['email'])) echo htmlentities(trim($_POST['email'])); ?>">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php echo $erreurs['email']['msg']; ?></td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">My password : </label></td>
    		<td colspan="3">
    		<input type="password" name="password" class="loginRemplissage" value="<?php if (isset($_POST['password'])) echo htmlentities(trim($_POST['password'])); ?>">
    		  <span class="error">*</span></td> 
      		<td colspan="2" class="error2"><?php echo $erreurs['password']['msg']; ?></td>
      		</tr>
    		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">Confirm password : </label></td>
    		<td colspan="3">
    		<input type="password" name="pass_confirm" class="loginRemplissage" value="<?php if (isset($_POST['pass_confirm'])) echo htmlentities(trim($_POST['pass_confirm'])); ?>">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2">&nbsp;</td>
      		</tr>
     
     
      		<tr>
      		  <td>&nbsp;</td>
      		  <td colspan="5"><?php if (isset($erreur2)) echo '<br />',$erreur2;  ?></td>
    		  </tr>
      		<tr>
      		  <td height="43"></td>
      		  <td colspan="5"> <input type="submit" name="inscription" class="AlignementCreateAccount" value="I create my account"/></td>
    		  </tr>
      		<tr>
      		  <td height="19">&nbsp;</td>
      		  <td colspan="5"><span class="error">*</span> <span class="error">Must be mandatory filled </span></td>
    		  </tr>
      		</table>
     
    		<p class="TexteFormulaireNombreProduits" id="contour_formulaire">&nbsp;</p> 	   
     
              </fieldset>     
      </form><br/>		   
    </div>
     
     
     
        </body>
        </html>

  9. #9
    Membre émérite
    Inscrit en
    Juillet 2003
    Messages
    625
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 625
    Par défaut
    Essayes avec ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
     
    <?php session_start();
     
    $base = mysql_connect ('localhost', 'root', ''); 
    mysql_select_db ('membres', $base);
     
    		if ( !empty($_POST) ) {
     
    			if ( $_POST['inscription'] == 'I create my account' ) {
     
    				// Initialisation des variables -isset détermine si variable est définie et différente de null
    				$email	= isset($_POST['email']) ? $_POST['email'] : '' ;
    				$password = isset($_POST['password']) ? $_POST['password'] : '' ;
    				$titre	= isset($_POST['titre']) ? $_POST['titre'] : '' ;
    				$prenom	= isset($_POST['prenom']) ? $_POST['prenom'] : '' ;
    				$nom	= isset($_POST['nom']) ? $_POST['nom'] : '' ;
    				$pass_confirm	= isset($_POST['pass_confirm']) ? $_POST['pass_confirm'] : '' ;
     
    				$tabErreur = array();
     
     
    					// on teste les deux mots de passe
    				if( strlen($_POST['prenom']) < 4 ) {
    					$tabErreur['prenom'] = ' Votre prenom doit comporter au minimun 4 caracteres !';
    				}
     
    				if( strlen($_POST['nom']) < 4 ) {
    					$tabErreur['nom'] = ' Votre nom doit comporter au minimun 4 caracteres !';
    				}
     
    				if( false === filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
    					$tabErreur['email'] = ' Votre Email n\'est pas valide !';
    				} 
    				if( strlen($_POST['password']) < 6 ) {
    					$tabErreur['password'] = ' Votre password doit comporter au minimun 6 caracteres !';
    				}
     
    				if ($_POST['password'] != $_POST['pass_confirm']) { 
    					$tabErreur['password2'] = 'Les 2 mots de passe sont différents.'; 
    				}
     
    				// on recherche si ce login est déjà utilisé par un autre membre
     
    				$sql = 'SELECT count(*) FROM membre WHERE email="'.mysql_escape_string($_POST['email']).'"'; 
    				$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error()); 
    				$data = mysql_fetch_array($req);
     
    				if ($data[0] > 0) {
    					$tabErreur['existant'] = 'Un membre possède déjà ce login.'; 
    				}
     
    				if ( empty($tabErreur)) {
     
    					$sql = 'INSERT INTO membre VALUES("",
    					"'.mysql_escape_string($email).'", 
    					"'.mysql_escape_string(md5($password)).'",
    					"'.mysql_escape_string($titre).'",
    					"'.mysql_escape_string($prenom).'",
    					"'.mysql_escape_string($nom).'","")'; 
     
    					mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error()); 
     
    					$_SESSION['email'] = $_POST['email']; 
    					header('Location: inscription2.php'); 
    					exit(); 
    				}
     
    			}
     
    		}
        ?>
        <html>
        <head>
        <title>Inscription</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link rel="stylesheet" href="StylesFormulaireAuthentification.css" type="text/css" charset="utf-8"/>
        </head>
     
        <body>
     
     
     
    	<div id="contour_formulaire">
     
            <form action="inscription3.php" method="post">
    		<fieldset style="border-color:#73aad2;border-size:2px;" width="625">  
    		<legend class="titre_labelaut"></legend>
     
    <br/>
     
     
    	<?php 
    	// Si il y a une/des erreur(s)
    	if( !empty($tabErreur['existant']) ) {
    	?>
    	<h3>Errreur(s)</h3>
    	<span><?php echo $tabErreur['existant']; ?></span>
    	<?php	
    	}
    	?>
     
    		<table width="628" border="0" cellpadding="0" cellspacing="0" >
     
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
     
    		  		  <tr>
        	<td width="132"> <label for="titre" class="TexteLogin">Title : </label></td>
    		<td width="59" class="TexteCheck"><label><input name="titre" type="radio"  value="Mr" checked="checked" />
    		  Mr &nbsp;&nbsp;&nbsp;</label></td>
      		<td width="80" class="TexteCheck"><label><input name="titre" type="radio" value="Mme" />Mme &nbsp;&nbsp;&nbsp;</label></td>
      		<td colspan="2" class="TexteCheck"><label><input name="titre" type="radio" value="Mlle" />
                Mlle</label></td>
      		<td width="280" class="error2"></td>
      		</tr>	  
     
     
      		<tr>
        	<td width="132"> <label for="prenom" class="TexteLogin">First Name : </label></td>
    		<td colspan="3">
    		<input type="text" name="prenom" class="loginRemplissage" value="<?php if (isset($_POST['prenom'])) echo htmlentities(trim($_POST['prenom'])); ?>"> 
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if ( !empty($tabErreur['prenom']) ) echo $tabErreur['prenom']; ?></td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="nom" class="TexteLogin">Family Name  : </label></td>
    		<td colspan="3">
    		<input type="text" name="nom" class="loginRemplissage" value="<?php if (isset($_POST['nom'])) echo htmlentities(trim($_POST['nom'])); ?>">		  
    		<span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if ( !empty($tabErreur['nom']) ) echo $tabErreur['nom']; ?></td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error2"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="email" class="TexteLogin">E-mail : </label></td>
    		<td colspan="3">
    		<input type="text" name="email" class="loginRemplissage" value="<?php if (isset($_POST['email'])) echo htmlentities(trim($_POST['email'])); ?>">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if ( !empty($tabErreur['email']) ) echo $tabErreur['email']; ?></td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">My password : </label></td>
    		<td colspan="3">
    		<input type="password" name="password" class="loginRemplissage" value="<?php if (isset($_POST['password'])) echo htmlentities(trim($_POST['password'])); ?>">
    		  <span class="error">*</span></td> 
      		<td colspan="2" class="error2"><?php if ( !empty($tabErreur['password']) ) echo $tabErreur['password']; ?></td>
      		</tr>
    		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">Confirm password : </label></td>
    		<td colspan="3">
    		<input type="password" name="pass_confirm" class="loginRemplissage" value="<?php if (isset($_POST['pass_confirm'])) echo htmlentities(trim($_POST['pass_confirm'])); ?>">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2">&nbsp;</td>
      		</tr>
     
      		  <td height="43"></td>
      		  <td colspan="5"> <input type="submit" name="inscription" class="AlignementCreateAccount" value="I create my account"/></td>
    		  </tr>
      		<tr>
      		  <td height="19">&nbsp;</td>
      		  <td colspan="5"><span class="error">*</span> <span class="error">Must be mandatory filled </span></td>
    		  </tr>
      		</table>
     
    			<p class="TexteFormulaireNombreProduits" id="contour_formulaire">&nbsp;</p> 	   
     
              </fieldset>     
      </form><br/>		   
    </div>
        </body>
        </html>

  10. #10
    Membre Expert
    Avatar de ska_root
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2005
    Messages
    1 203
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Service public

    Informations forums :
    Inscription : Août 2005
    Messages : 1 203
    Par défaut
    Citation Envoyé par LiliValerie Voir le message
    Et le tableau indicé pour ska_root pour lequel j'ai des erreurs notices, variables non définies
    évidemment, regarde bien, l'initialisation du tableau $erreurs se trouve en dehors de la condition if(isset($_POST["inscription"])) dans mon exemple.

    ce n'est pas le cas dans ton code...

  11. #11
    Membre confirmé
    Inscrit en
    Juillet 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 107
    Par défaut
    Merci beaucoup pour votre aide à tous les deux.
    Syl2095, ta solution fonctionne très bien, je te remercie.
    Ska_root, il faut que je ressaye à nouveau parce que je n'arrive pas à le positionner au bon endroit le if(isset($_POST["inscription"])), je ne suis pas douée du tout...
    En attendant, merci de m'avoir aidée

  12. #12
    Membre Expert
    Avatar de ska_root
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2005
    Messages
    1 203
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Service public

    Informations forums :
    Inscription : Août 2005
    Messages : 1 203
    Par défaut correction de l'exemple (oups)
    de rien, et si ton code fonctionne maintenant, tant mieux, je ne suis pas là pour gagner un concours de toute façon...

    pour le fun (et accessoirement pour ta connaissance) voici ton code modifié :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    <?php
    session_start(); // toujours en premier dans la page !!!
     
     
    // on initialise le tableau des erreurs
    $erreurs= array(
       "titre" =>        array("msg" => ""),
       "nom" =>          array("msg" => ""),
       "prenom" =>       array("msg" => ""),
       "email" =>        array("msg" => ""),
       "password" =>     array("msg" => ""),
       "pass_confirm" => array("msg" => "")
    );
    $error_exist= false;
    $erreur= "";
     
    $titre=        (isset($_POST['titre']))         ?($_POST['titre'])         :("");
    $nom=          (isset($_POST['nom']))           ?($_POST['nom'])           :("");
    $prenom=       (isset($_POST['prenom']))        ?($_POST['prenom'])        :("");
    $email=        (isset($_POST['email']))         ?($_POST['email'])         :("");
    $password=     (isset($_POST['password']))      ?($_POST['password'])      :("");
    $pass_confirm= (isset($_POST['pass_confirm']))  ?($_POST['pass_confirm'])  :("");
     
     // on teste si le visiteur a soumis le formulaire
    if(isset($_POST['inscription'])) {
     
       if(empty($titre) || empty($nom) || empty($prenom) || empty($email) || empty($password) || empty($pass_confirm)) {
          $erreur = "Tous les champs sont requis !"; 
          $error_exist= true;  
       }
     
       // test sur nom
       $nom_ko= (strlen($nom) < 4);
       if($nom_ko) {
           $erreurs["nom"]["msg"].="Votre nom doit comporter au minimun 4 caracteres !<br/>";
           $error_exist= true;
       } 
     
       // test sur prenom
       $prenom_ko= (strlen($prenom) < 4);
       if($prenom_ko) {
           $erreurs["prenom"]["msg"].="Votre prénom doit comporter au minimun 4 caracteres !<br/>";
           $error_exist= true;
       } 
     
       // test sur mot de passe
       $pass_ko=(strlen($password) < 6);
       if($pass_ko) {
           $erreurs["password"]["msg"].="Votre password doit comporter au minimun 6 caracteres !<br/>";
           $error_exist= true;
       }
       if($password != $pass_confirm) {
          $erreurs["password"]["msg"].= "Les 2 mots de passe sont différents !<br/>";
          $error_exist= true;
       }
     
       // test sur email
       if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
          $erreurs["email"]["msg"].= "Votre Email n\'est pas valide !<br/>";
       }
     
       if(!$error_exist) {
     
          $base = mysql_connect ('localhost', 'root', ''); 
          mysql_select_db ('membres', $base); 
     
          // on recherche si ce login est déjà utilisé par un autre membre
          $sql = 'SELECT count(*) FROM membre WHERE email="'.mysql_escape_string($email).'"'; 
          $req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error()); 
          $data = mysql_fetch_array($req); 
     
    	   // si cet email n'est pas déjà présent dans la table, on peut l'enregistrer $data = 0
          if ($data[0] == 0) { 
             $sql = "INSERT INTO membre VALUES('',
    			      '".mysql_escape_string($email)."', 
                   '".mysql_escape_string(md5($password))."',
    				   '".mysql_escape_string($titre)."',
    				   '".mysql_escape_string($prenom)."',
    				   '".mysql_escape_string($nom)."',
    				   '')"; 
     
             mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error()); 
     
    	 	   // et on commence la session qui s'appelle email
             $_SESSION['email'] = $email; 
             header('Location: inscription2.php'); 
             exit(); 
          } 
          else { 
             $erreur = 'Un membre possède déjà ce login.'; 
          } 
       } 
    } 
    ?>
        <html>
        <head>
        <title>Inscription</title>
     
        </head>
     
        <body>
     
     
     
    	<div id="contour_formulaire">
     
            <form action="inscription.php" method="post">
    		<fieldset style="border-color:#73aad2;border-size:2px;" width="625">  
    		<legend class="titre_labelaut">Open your personal Interchim web account &amp; get benefit of many advantages   :</legend>
     
     
     
        <br/>              
    		<table width="628" border="0" cellpadding="0" cellspacing="0" >
     
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
     
    		  		  <tr>
        	<td width="132"> <label for="titre" class="TexteLogin">Title : </label></td>
    		<td width="59" class="TexteCheck"><label><input name="titre" type="radio"  value="Mr" checked="checked" />
    		  Mr &nbsp;&nbsp;&nbsp;</label></td>
      		<td width="80" class="TexteCheck"><label><input name="titre" type="radio" value="Mme" />Mme &nbsp;&nbsp;&nbsp;</label></td>
      		<td colspan="2" class="TexteCheck"><label><input name="titre" type="radio" value="Mlle" />
                Mlle</label></td>
      		<td width="280" class="error2"></td>
      		</tr>	  
     
     
      		<tr>
        	<td width="132"> <label for="prenom" class="TexteLogin">First Name : </label></td>
    		<td colspan="3">
    		<input type="text" name="prenom" class="loginRemplissage" value="<?php echo $prenom; ?>"> 
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"> <?php echo $erreurs["prenom"]["msg"]; ?>
    		</td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="nom" class="TexteLogin">Family Name  : </label></td>
    		<td colspan="3">
    		<input type="text" name="nom" class="loginRemplissage" value="<?php echo $nom; ?>">		  
    		<span class="error">*</span></td>
      		<td colspan="2" class="error2"> <?php echo $erreurs["nom"]["msg"]; ?>
    		</td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error2"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="email" class="TexteLogin">E-mail : </label></td>
    		<td colspan="3">
    		<input type="text" name="email" class="loginRemplissage" value="<?php echo $email; ?>">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"> <?php echo $erreurs["email"]["msg"]; ?>
    		</td>
      		</tr>
      		<tr>
      		  <td colspan="6" class="error"></td>
      		  </tr>
      		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">My password : </label></td>
    		<td colspan="3">
    		<input type="password" name="password" class="loginRemplissage" value="">
    		  <span class="error">*</span></td> 
      		<td colspan="2" class="error2"><?php if(isset($error_password)){ echo $error_password; } ?>
    		</td>
      		</tr>
    		<tr>
        	<td width="132"> <label for="password" class="TexteLogin">Confirm password : </label></td>
    		<td colspan="3">
    		<input type="password" name="pass_confirm" class="loginRemplissage" value="">
    		  <span class="error">*</span></td>
      		<td colspan="2" class="error2"><?php if(isset($error_password)){ echo $error_password; } ?>
    		</td>
      		</tr>
     
     
      		<tr>
      		  <td>&nbsp;</td>
      		  <td colspan="5"><?php if (isset($erreur)) echo '<br />',$erreur;  ?></td>
    		  </tr>
      		<tr>
      		  <td height="43"></td>
      		  <td colspan="5"> <input type="submit" name="inscription" class="AlignementCreateAccount" value="I create my account"/></td>
    		  </tr>
      		<tr>
      		  <td height="19">&nbsp;</td>
      		  <td colspan="5"><span class="error">*</span> <span class="error">Must be mandatory filled </span></td>
    		  </tr>
      		</table>
     
     
              </fieldset>     
      </form><br/>		   
    </div>
     
     
     
        </body>
        </html>
    voila, bonne analyse...

  13. #13
    Membre confirmé
    Inscrit en
    Juillet 2009
    Messages
    107
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 107
    Par défaut
    Merci ska_root, je vais étudier ça. J'ai essayé de travailler sur les deux solutions proposées et ça m'aide beaucoup pour progresser.
    Merci beaucoup encore à tous les deux pour votre aide rapide et efficace

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Verification de formulaire en php?
    Par hugo69 dans le forum Langage
    Réponses: 4
    Dernier message: 05/12/2006, 19h02
  2. [MySQL] Formulaires php et sauvegarde de donnees
    Par curtis2006 dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 27/10/2006, 15h13
  3. [PHP-JS] verification de formulaire
    Par car00x dans le forum Langage
    Réponses: 3
    Dernier message: 03/10/2006, 11h28
  4. [MySQL] Problème transfert donnees entre 2 formulaires php.
    Par pgil dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 17/01/2006, 15h00
  5. [MySQL] Formulaire php + bdd = perte des sauts de ligne html ?
    Par sunshine33 dans le forum PHP & Base de données
    Réponses: 8
    Dernier message: 03/10/2005, 11h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo