-2

I have 3 web pages one for sign-in, one for sign-up, and the last one is the home page (index). I have 2 variables from the sign-in and 5 variable from sign-up, all the variables are sent into the home page so when I sign up in the sign-in variable have no values so it gives an error "notice undefined index", and when I sign up the same happens but the error shows the sign in's variables. I have so many searches in google and I've found a function called unset to disable the variables, but nothing happens.

// Sous WAMP
$bdd = new PDO('mysql:host=localhost;dbname=test exbook;charset=utf8', 'root', '');
$reponse = $bdd->query('SELECT * FROM registration');
$nom = $_POST['nom'];
$birthday = $_POST['birthday'];
$genre = $_POST['genre'];
$email = $_POST['email'];
$password = password_hash($_POST['password'], PASSWORD_DEFAULT);

if (isset($nom , $birthday , $genre , $email, $password )) {
    unset($nom);
    unset($birthday);
    unset($genre);
    unset($email);
    unset($password);
} else {
    $req = $bdd->prepare('INSERT INTO registration(`Nom`, `Date de naissance`, `Genre`, `Email`, `Password`) VALUES(?,?,?,?,?)');
    $req->execute(array($nom, $birthday, $genre, $email, $password));
}

while ($donnees = $reponse->fetch()) {
    echo $donnees['Nom'];
}

$bdd = new PDO('mysql:host=localhost;dbname=test exbook;charset=utf8', 'root', '');
$emailsignup = $_POST['emailsignup'];
if (isset($emailsignup)) {
    unset($emailsignup);
} else{
    $bdd1 = $bdd->query('SELECT * FROM registration WHERE $emailsignup');
}

Thank you for reading this, and for trying to help. Have a nice day :)

Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

-2

The undefined index error is coming from $_POST variable. When you are trying to emailsignup the parameters nom, birthday... are not present in $_POST array. You can do something like this:

           // Sous WAMP
            $bdd = new PDO('mysql:host=localhost;dbname=test exbook;charset=utf8', 'root', '');
            $reponse = $bdd ->query('SELECT * FROM registration');
            $hasnom=isset($_POST['nom']);
            $hasbirthday=isset($_POST['birthday']);
            $hasgenre=isset($_POST['genre']);
            $hasemail=isset($_POST['email']);
            $haspass = $isset($_POST['pass']);


            if ($hasnom && $hasbirthday && $hasgenre && hasemail && haspass) {
              $nom=$_POST['nom'];
              $birthday=$_POST['birthday'];
              $genre=$_POST['genre'];
              $email=$_POST['email'];
              $password=password_hash($_POST['password'], PASSWORD_DEFAULT);

                $req = $bdd ->prepare('INSERT INTO registration(`Nom`, `Date de naissance`, `Genre`, `Email`, `Password`) VALUES(?,?,?,?,?)');
                $req->execute(array($nom,$birthday,$genre,$email,$password));   
             }
              while ($donnees = $reponse->fetch())
              {
                echo $donnees['Nom'];
              }
          ?>
          <?php
                $bdd = new PDO('mysql:host=localhost;dbname=test exbook;charset=utf8', 'root', '');
                $hasemailsignup=isset($_POST['emailsignup']);
                if ($hasemailsignup) {
                    $emailsignup = $_POST['emailsignup'];
                    $bdd1=$bdd ->query('SELECT * FROM registration WHERE $emailsignup');
                }
             ?>
Sakibur Rahman
  • 834
  • 3
  • 10
  • 26