Comment modifier une information dans ma BDD

Fermé
Energy_Wolf Messages postés 1 Date d'inscription mercredi 15 août 2018 Statut Membre Dernière intervention 15 août 2018 - Modifié le 15 août 2018 à 13:35
jordane45 Messages postés 38144 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 21 avril 2024 - 15 août 2018 à 13:37
Bonjour tous le monde donc voici mes codes et j'aimerais savoir comment les modifiers une fois qu'ils sont enregistrer dans la BDD

<?php

include( "config.php" );

if(isset($_POST['forminscription'])) {
   $pseudo = htmlspecialchars($_POST['pseudo']);
   $mail = htmlspecialchars($_POST['mail']);
   $mail2 = htmlspecialchars($_POST['mail2']);
   $mdp = sha1($_POST['mdp']);
   $mdp2 = sha1($_POST['mdp2']);
   if(!empty($_POST['pseudo']) AND !empty($_POST['mail']) AND !empty($_POST['mail2']) AND !empty($_POST['mdp']) AND !empty($_POST['mdp2'])) {
      $pseudolength = strlen($pseudo);
      if($pseudolength <= 32) {
         if($mail == $mail2) {
            if(filter_var($mail, FILTER_VALIDATE_EMAIL)) {
               $reqmail = $bdd->prepare("SELECT * FROM membres WHERE mail = ?");
               $reqmail->execute(array($mail));
               $mailexist = $reqmail->rowCount();
               if($mailexist == 0) {
                  if($mdp == $mdp2) {
                     $insertmbr = $bdd->prepare("INSERT INTO membres(pseudo, mail, motdepasse) VALUES(?, ?, ?)");
                     $insertmbr->execute(array($pseudo, $mail, $mdp));
                     $erreur = "Your account has been created! <a href=\"login.php\">Login Here</a>";
                  } else {
                     $erreur = "Passwords do not match!";
                  }
               } else {
                  $erreur = "Email is already in use!";
               }
            } else {
               $erreur = "Your email address is invalid!";
            }
         } else {
            $erreur = "Password do not match!";
         }
      } else {
         $erreur = "Username can be a maximum of 32 characters!";
      }
   } else {
      $erreur = "All of the fields must be filled!";
   }
}
?>
<html>
   <head>
      <title>LSPD</title>
      <meta charset="utf-8">
   </head>
   <body>
      <div align="center">
         <h2>Registration</h2>
         <br /><br />
         <form method="POST" action="">
            <table>
               <tr>
                  <td align="right">
                     <label for="pseudo">Username  :</label>
                  </td>
                  <td>
                     <input type="text" placeholder="Username" id="pseudo" name="pseudo" value="<?php if(isset($pseudo)) { echo $pseudo; } ?>" />
                  </td>
               </tr>
               <tr>
                  <td align="right">
                     <label for="mail">Email :</label>
                  </td>
                  <td>
                     <input type="email" placeholder="Email Address" id="mail" name="mail" value="<?php if(isset($mail)) { echo $mail; } ?>" />
                  </td>
               </tr>
               <tr>
                  <td align="right">
                     <label for="mail2">Confirm Email :</label>
                  </td>
                  <td>
                     <input type="email" placeholder="Confirm Email" id="mail2" name="mail2" value="<?php if(isset($mail2)) { echo $mail2; } ?>" />
                  </td>
               </tr>
               <tr>
                  <td align="right">
                     <label for="mdp">Password :</label>
                  </td>
                  <td>
                     <input type="password" placeholder="Password" id="mdp" name="mdp" />
                  </td>
               </tr>
               <tr>
                  <td align="right">
                     <label for="mdp2">Confirm Password :</label>
                  </td>
                  <td>
                     <input type="password" placeholder="Confirm Password" id="mdp2" name="mdp2" />
                  </td>
               </tr>
               <tr>
                  <td></td>
                  <td align="center">
                     <br />
                     <input type="submit" name="forminscription" value="Sign up" />
                  </td>
               </tr>
            </table>
         </form>
         <?php
         if(isset($erreur)) {
            echo '<font color="red">'.$erreur."</font>";
         }
         ?>
      </div>
   </body>
</html>


Voici mon code pour s'enregistrer

et j'aimerais savoir si par un autre lien php il pourrai modifier son adresse mail par exemple

J'ai essayer ceci mais sans resultat :
<?php
include( "config.php" );
?>


<html>

<form name="test" action="test.php" method="POST">
  <table border="0" align="center" cellspacing="2" cellpadding="2">
    <tr align="center">
      <td>nom</td>
      <td><input type="text" name="pseudo" id="pseudo"></td>
    </tr>
    <tr align="center">
      <td>email</td>
      <td><input type="text" name="mail" id="mail"></td>
    </tr>
    <tr align="center">
      <td colspan="2"><input type="submit" value="modifier"></td>
    </tr>
  </table>
</form>

<?php


$pseudo = $_POST["pseudo"]; 



$mail = $_POST["mail"];



// on teste si les variables du formulaire sont déclarées
if (isset($_POST['mail']) && isset($_POST['pseudo'])) {

 // lancement de la requête
 $sql = 'UPDATE membres SET mail= '$nom' WHERE pseudo= '$pseudo' ';

 // on exécute la requête (mysql_query) et on affiche un message au cas où la requête ne se passait pas bien (or die)
 mysql_query($sql) or die('Erreur SQL !'.$sql.'<br />'.mysql_error());

 // on ferme la connexion à la base
 mysql_close();

 // un petit message permettant de se rendre compte de la modification effectuée
 echo 'La nouvelle adresse de '.$_POST['pseudo'].' est : '.$_POST['mail'];
}
else {
 echo 'Les variables du formulaire ne sont pas déclarées';
}
?>

</html>


EDIT : Correction des balises de code

Voila j'espere avoir de l'aide
Je vous remercie
Aurevoir
A voir également:

1 réponse

jordane45 Messages postés 38144 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 21 avril 2024 4 650
15 août 2018 à 13:37
Bonjour,

1 - Pour poster ton code sur le forum, tu dois utiliser les balises de code
explications ici : https://codes-sources.commentcamarche.net/faq/11288-poster-un-extrait-de-code

2 - Dans ton premier code tu utilises PDO ..... mais dans le second tu as réutilisé l'ancienne extension mysql_* ... ce qui ne peut pas marcher !
Tu dois réécrire ton code en PDO.

3 - Pour voir les éventuelles erreurs dans ton code tu dois activer l'affichage des erreurs PHP ainsi que les erreurs PDO.
Voici comment faire :
https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs
et ceci :
https://forums.commentcamarche.net/forum/affich-37584947-php-gestion-des-erreurs-debogage-et-ecriture-du-code


0