Problème espace Membre

Fermé
sachadupuy - Modifié par jordane45 le 27/02/2015 à 13:22
jordane45 Messages postés 38358 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 28 décembre 2024 - 27 févr. 2015 à 13:29
Bonjour,

Je suis entrain de faire un espace membre pour mon site mais j'ai un problème:
Après avoir rempli le formulaire d'enregistrement, et cliquer sur le bouton submit, les informations ne se rentrent pas dans la base de données:

register.php:

<!DOCTYPE html>
<html>
<?php include_once('../../fonctions.php');
require_once('app/db.php');
 ?>
<head>
 <link href="../css/bootstrap.css" rel=stylesheet>
 <meta charset="utf-8" />
 <title>Inscription - faceSchool</title>
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body class="blurBg-false" style="background-color:#EBEBEB">
 


<link rel="stylesheet" href="form_files/faceSchoolreg/formoid-solid-blue.css" type="text/css" />
<script type="text/javascript" src="form_files/faceSchoolreg/jquery.min.js"></script>
<form action="register.php" method="post" class="formoid-solid-blue" style="background-color:#FFFFFF;font-size:14px;font-family:'Roboto',Arial,Helvetica,sans-serif;color:#34495E;max-width:480px;min-width:150px" method="post"><div class="title"><h2>Inscription</h2></div>
 <div class="element-input"><label class="title"></label><div class="item-cont"><input class="large" type="text" name="pseudo" id="pseudo" placeholder="Pseudonyme"/><span class="icon-place"></span></div></div>
 <div class="element-password"><label class="title"></label><div class="item-cont"><input class="large" type="password" id="password" name="password" value="" placeholder="Mot de Passe"/><span class="icon-place"></span></div></div>
 <div class="element-password"><label class="title"></label><div class="item-cont"><input class="large" type="password" id="passwordconfirm" name="passwordconfirm" value="" placeholder="Mot de Passe(Confirmation)"/><span class="icon-place"></span></div></div>
 <div class="element-email"><label class="title"></label><div class="item-cont"><input class="large" type="email" name="email" value="" placeholder="Email"/><span class="icon-place"></span></div></div>
 <div class="element-address"><label class="title"></label><span class="addr1"><input placeholder="Adresse" type="text" name="address[addr1]" /><span class="icon-place"></span></span><span class="addr2"><input placeholder="Addresse (suite)" type="text" name="address[addr2]" /><span class="icon-place"></span></span><span class="city"><input placeholder="Ville" type="text" name="address[city]" /><span class="icon-place"></span></span><span class="state"><input placeholder="Etat/Province/Region" type="text" name="address[state]" /><span class="icon-place"></span></span><span class="zip"><input placeholder="Code Postal" type="text" maxlength="15" name="zipcode" /><span class="icon-place"></span></span><div class="country"><select name="address[country]" ><option selected="selected" value="" disabled="disabled">--- Choisir un Pays ---</option><option value="United States">United States</option><option value="United Kingdom">United Kingdom</option><option value="Australia">Australia</option><option value="Canada">Canada</option><option value="France">France</option><option value="New Zealand">New Zealand</option><option value="India">India</option><option value="Brazil">Brazil</option><option value="----" disabled="disabled">----</option><option value="Afghanistan">Afghanistan</option><option value="Aland Islands">Aland Islands</option><option value="Albania">Albania</option><option value="Algeria">Algeria</option><option value="American Samoa">American Samoa</option><option value="Andorra">Andorra</option><option value="Angola">Angola</option><option value="Anguilla">Anguilla</option><option value="Antarctica">Antarctica</option><option value="Antigua and Barbuda">Antigua and Barbuda</option><option value="Argentina">Argentina</option><option value="Armenia">Armenia</option><option value="Aruba">Aruba</option><option value="Austria">Austria</option><option value="Azerbaijan">Azerbaijan</option><option value="Bahamas">Bahamas</option><option value="Bahrain">Bahrain</option><option value="Bangladesh">Bangladesh</option><option value="Barbados">Barbados</option><option value="Belarus">Belarus</option><option value="Belgium">Belgium</option><option value="Belize">Belize</option><option value="Benin">Benin</option><option value="Bermuda">Bermuda</option><option value="Bhutan">Bhutan</option><option value="Bolivia">Bolivia</option><option value="Bosnia and Herzegovina">Bosnia and Herzegovina</option><option value="Botswana">Botswana</option><option value="British Indian Ocean Territory">British Indian Ocean Territory</option><option value="Brunei Darussalam">Brunei Darussalam</option><option value="Bulgaria">Bulgaria</option><option value="Burkina Faso">Burkina Faso</option><option value="Burundi">Burundi</option><option value="Cambodia">Cambodia</option><option value="Cameroon">Cameroon</option><option value="Cape Verde">Cape Verde</option><option value="Cayman Islands">Cayman Islands</option><option value="Central African Republic">Central African Republic</option><option value="Chad">Chad</option><option value="Chile">Chile</option><option value="China">China</option><option value="Colombia">Colombia</option><option value="Comoros">Comoros</option><option value="Democratic Republic of the Congo">Democratic Republic of the Congo</option><option value="Republic of the Congo">Republic of the Congo</option><option value="Cook Islands">Cook Islands</option><option value="Costa Rica">Costa Rica</option><option value="Cote d'Ivoire">Cote d'Ivoire</option><option value="Croatia">Croatia</option><option value="Cuba">Cuba</option><option value="Cyprus">Cyprus</option><option value="Czech Republic">Czech Republic</option><option value="Denmark">Denmark</option><option value="Djibouti">Djibouti</option><option value="Dominica">Dominica</option><option value="Dominican Republic">Dominican Republic</option><option value="East Timor">East Timor</option><option value="Ecuador">Ecuador</option><option value="Egypt">Egypt</option><option value="El Salvador">El Salvador</option><option value="Equatorial Guinea">Equatorial Guinea</option><option value="Eritrea">Eritrea</option><option value="Estonia">Estonia</option><option value="Ethiopia">Ethiopia</option><option value="Faroe Islands">Faroe Islands</option><option value="Fiji">Fiji</option><option value="Finland">Finland</option><option value="Gabon">Gabon</option><option value="Gambia">Gambia</option><option value="Georgia">Georgia</option><option value="Germany">Germany</option><option value="Ghana">Ghana</option><option value="Gibraltar">Gibraltar</option><option value="Greece">Greece</option><option value="Grenada">Grenada</option><option value="Guatemala">Guatemala</option><option value="Guinea">Guinea</option><option value="Guinea-Bissau">Guinea-Bissau</option><option value="Guyana">Guyana</option><option value="Haiti">Haiti</option><option value="Honduras">Honduras</option><option value="Hong Kong">Hong Kong</option><option value="Hungary">Hungary</option><option value="Iceland">Iceland</option><option value="Indonesia">Indonesia</option><option value="Iran">Iran</option><option value="Iraq">Iraq</option><option value="Ireland">Ireland</option><option value="Israel">Israel</option><option value="Italy">Italy</option><option value="Jamaica">Jamaica</option><option value="Japan">Japan</option><option value="Jordan">Jordan</option><option value="Kazakhstan">Kazakhstan</option><option value="Kenya">Kenya</option><option value="Kiribati">Kiribati</option><option value="North Korea">North Korea</option><option value="South Korea">South Korea</option><option value="Kuwait">Kuwait</option><option value="Kyrgyzstan">Kyrgyzstan</option><option value="Laos">Laos</option><option value="Latvia">Latvia</option><option value="Lebanon">Lebanon</option><option value="Lesotho">Lesotho</option><option value="Liberia">Liberia</option><option value="Libya">Libya</option><option value="Liechtenstein">Liechtenstein</option><option value="Lithuania">Lithuania</option><option value="Luxembourg">Luxembourg</option><option value="Macedonia">Macedonia</option><option value="Madagascar">Madagascar</option><option value="Malawi">Malawi</option><option value="Malaysia">Malaysia</option><option value="Maldives">Maldives</option><option value="Mali">Mali</option><option value="Malta">Malta</option><option value="Marshall Islands">Marshall Islands</option><option value="Mauritania">Mauritania</option><option value="Mauritius">Mauritius</option><option value="Mexico">Mexico</option><option value="Micronesia">Micronesia</option><option value="Moldova">Moldova</option><option value="Monaco">Monaco</option><option value="Mongolia">Mongolia</option><option value="Montenegro">Montenegro</option><option value="Morocco">Morocco</option><option value="Mozambique">Mozambique</option><option value="Myanmar">Myanmar</option><option value="Namibia">Namibia</option><option value="Nauru">Nauru</option><option value="Nepal">Nepal</option><option value="Netherlands">Netherlands</option><option value="Netherlands Antilles">Netherlands Antilles</option><option value="Nicaragua">Nicaragua</option><option value="Niger">Niger</option><option value="Nigeria">Nigeria</option><option value="Norway">Norway</option><option value="Oman">Oman</option><option value="Pakistan">Pakistan</option><option value="Palau">Palau</option><option value="Palestine">Palestine</option><option value="Panama">Panama</option><option value="Papua New Guinea">Papua New Guinea</option><option value="Paraguay">Paraguay</option><option value="Peru">Peru</option><option value="Philippines">Philippines</option><option value="Poland">Poland</option><option value="Portugal">Portugal</option><option value="Puerto Rico">Puerto Rico</option><option value="Qatar">Qatar</option><option value="Romania">Romania</option><option value="Russia">Russia</option><option value="Rwanda">Rwanda</option><option value="Saint Kitts and Nevis">Saint Kitts and Nevis</option><option value="Saint Lucia">Saint Lucia</option><option value="Saint Vincent and the Grenadines">Saint Vincent and the Grenadines</option><option value="Samoa">Samoa</option><option value="San Marino">San Marino</option><option value="Sao Tome and Principe">Sao Tome and Principe</option><option value="Saudi Arabia">Saudi Arabia</option><option value="Senegal">Senegal</option><option value="Serbia">Serbia</option><option value="Seychelles">Seychelles</option><option value="Sierra Leone">Sierra Leone</option><option value="Singapore">Singapore</option><option value="Slovakia">Slovakia</option><option value="Slovenia">Slovenia</option><option value="Solomon Islands">Solomon Islands</option><option value="Somalia">Somalia</option><option value="South Africa">South Africa</option><option value="Spain">Spain</option><option value="Sri Lanka">Sri Lanka</option><option value="Sudan">Sudan</option><option value="Suriname">Suriname</option><option value="Swaziland">Swaziland</option><option value="Sweden">Sweden</option><option value="Switzerland">Switzerland</option><option value="Syria">Syria</option><option value="Taiwan">Taiwan</option><option value="Tajikistan">Tajikistan</option><option value="Tanzania">Tanzania</option><option value="Thailand">Thailand</option><option value="Togo">Togo</option><option value="Tonga">Tonga</option><option value="Trinidad and Tobago">Trinidad and Tobago</option><option value="Tunisia">Tunisia</option><option value="Turkey">Turkey</option><option value="Turkmenistan">Turkmenistan</option><option value="Tuvalu">Tuvalu</option><option value="Uganda">Uganda</option><option value="Ukraine">Ukraine</option><option value="United Arab Emirates">United Arab Emirates</option><option value="United States Minor Outlying Islands">United States Minor Outlying Islands</option><option value="Uruguay">Uruguay</option><option value="Uzbekistan">Uzbekistan</option><option value="Vanuatu">Vanuatu</option><option value="Vatican City">Vatican City</option><option value="Venezuela">Venezuela</option><option value="Vietnam">Vietnam</option><option value="Virgin Islands, British">Virgin Islands, British</option><option value="Virgin Islands, U.S.">Virgin Islands, U.S.</option><option value="Yemen">Yemen</option><option value="Zambia">Zambia</option><option value="Zimbabwe">Zimbabwe</option></select><i></i><span class="icon-place"></span></div></div>
<div class="submit"><input type="submit" value="S'inscrire"/></div></form><p class="frmd"><script type="text/javascript" src="form_files/faceSchoolreg/formoid-solid-blue.js"></script>

<?php 

if(isset($_POST['pseudo']) && isset($_POST['email']) && isset($_POST['password']) && isset($_POST['adress[addr1]']) && isset($_POST['adress[city]']) && isset($_POST['adress_country']))
{
 echo('TEST');
 echo($message);
 $identifiant = addslashes(htmlspecialchars(htmlentities(trim($_POST['pseudo']))));
 $email = addslashes(htmlspecialchars(htmlentities(trim($_POST['email']))));
 $addr1 = addslashes(htmlspecialchars(htmlentities(trim($_POST['adress[addr1]']))));
 $addr2 = addslashes(htmlspecialchars(htmlentities(trim($_POST['adress[city]']))));
 $addrpays = addslashes(htmlspecialchars(htmlentities(trim($_POST['adress[country]']))));
 $password = sha1($_POST['password']);
 $passwordconfirm = sha1($_POST['passwordconfirm']);
 if(strlen($identifiant) > 6) {
  if(strlen($email) < 255) {
   if(preg_match("#^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$#", $email)) {
    if($password == $passwordconfirm) {
     $req = $bdd->query("SELECT identifiant FROM membres WHERE identifiant = '$identifiant'");
     $count = $req->rowCount();
     if($count == 0) {
      $req = $bdd->query("SELECT email FROM membres WHERE email = '$email'");
      $count = $req->rowCount();
      if($count == 0) {
        $req = array(
          'identifiant' => $identifiant,
          'password' => $password,
          'email' => $email,
          'pays' => $addrpays,
          'addresse' => $addr1 
         );
       $req = $bdd->prepare("INSERT into membres(identifiant, password, email, pays, adresse) VALUES('$identifiant', '$password', '$email', '$addrpays', 'addr1')");
       $req->execute();
       if ( $req->execute() == false ) { // si l'éxecution de la requête renvoit une erreur
   echo $req->errorInfo(); // tu affiches l'erreur pour voir ou ça plante
}
      } else {
       $message = 'Cet email est déjà utilisé';
      }
     } else{
      $message = 'Cet identifiant est déjà utilisé!';
     }
    }
   } else {
    $message = 'Votre adresse email n\'est pas valide';
   }
  }

 } else {
  $msgerreur = 'Votre identifiant est trop court';
 }
}
else {
 $msgerreur = 'Les champs ne sont pas tous remplis';
}


 ?>


</body>
</html>


EDIT : Ajout des balises de code
A voir également:

1 réponse

jordane45 Messages postés 38358 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 28 décembre 2024 4 719
Modifié par jordane45 le 27/02/2015 à 13:29
Bonjour,


Déjà.... places plutôt le traitement PHP au début de ta page (avec le HTML) plutôt qu'en dessous....

Ensuite.....
Tu créés un array de param ....
 $req = array(
          'identifiant' => $identifiant,
          'password' => $password,
          'email' => $email,
          'pays' => $addrpays,
          'addresse' => $addr1 
         );

mais tu ne l'utilises pas dans ta requête

Et enfin... tu as écris :
 $req = $bdd->prepare("INSERT into membres(identifiant, password, email, pays, adresse) VALUES('$identifiant', '$password', '$email', '$addrpays', 'addr1')");

Comme tu peux le voir...il manque un $ devant ton dernier champ .....

Mais vu que tu as un tableau de param... pourquoi écrire les variables directement dans ta requête ??

Tu ferais mieux de :
1 - Séparer la requête des instructions
2 - Utiliser ton tableau de param....

$params = array(
    'identifiant' => $identifiant,
    'password' => $password,
    'email' => $email,
    'pays' => $addrpays,
    'addresse' => $addr1 
    );
$sql = "INSERT into membres
        (identifiant , password  , email  ,  pays      , adresse) 
   VALUES(':identifiant',':password',':email',':pays', ':addresse')";  
$req = $bdd->prepare($sql);
$req->execute($params);







Cordialement,
Jordane
0