0

I'm sorry because I'm a beginner in php and also in stack, I already asked my question but it gives me limited because of the signal, thank you for helping me without reporting and thank you very much.

i Create an "index.html" page which asks the user for a username and a password, This form redirects to a "forme.php" page, which contains fields to be filled in by the user, when I enter them user data and I click on the resume button, the button will redirect me to resume.php and display my user data, but I also want to display the identifier that entered in the 1st form, it gives me error:Undefined variable: login in D:\wamp\www\tp\resume.php on line 9 .

index.html

<form method="post" action="formulaire.php">
          <label>login</label>
          <input name="login" type="text">
          <br>
          <label>mot de pass</label>
          <input name="password" type="password">
          <br>
          <input name="Submit" type="submit" value="Enregistrer">
       </form>  

formulaire.php

<?php
       $login=$_POST["login"];
       $password=$_POST["password"];


       if($login!="aaaaa" && $password!="aaaaa"){
        echo "<p style='color:red';>vous avez pas le droit d'acceder a cette page</p>";
       }else { ?>
         <form method="post" action="resume.php">
          <label>email</label>
          <input name="email" type="text">
          <br>
          Genre:
          <input type="radio" name="gender" value="female">F
          <input type="radio" name="gender" value="male">M
          <input type="radio" name="gender" value="Autre">Autre
          <br>
          <label>citation préféré</label>
          <input type="textarea" name="citation" style="height: 50px;width:450px;">
           
          </input>
          <br>
          <label>L'auteur</label>
          <input name="auteur" type="text">
          <br>
          <label for="pet-select">nombre d'ouvrage:</label>
          <select name="ouvrage" id="pet-select">
              <option value="">--Please choose an option--</option>
              <option value="1">1</option>
              <option value="2">2</option>
              <option value="3">3</option>
              <option value="4">4</option>
              <option value="5">5</option>
              <option value="6">6</option>
          </select>
          <br>
          <input type="checkbox" name="ouvrage1" value="ouvrage1">
          <label for="ouvrage1">ouvrage 1</label>
          <br>
          <input type="checkbox" name="ouvrage2" value="ouvrage2">
          <label for="ouvrage2">ouvrage 2</label>
          <br>
          <input name="Submit" type="submit" value="resume">
         </form> 
       <?php } ?>

resume.php

<h1><?php echo $login ?></h1>
    <?php 
       $email    = $_POST["email"];
       $gender   = $_POST["gender"];
       $citation = $_POST["citation"];
       $auteur   = $_POST["auteur"];
       $ouvrage  = $_POST["ouvrage"];
       $ouvrage1 = $_POST["ouvrage1"];
       $ouvrage2 = $_POST["ouvrage2"];
       echo "email : " .$email."||genre : ".$gender."||ciattion : ".$citation."|| auteur : ".$auteur."|| ouvrage : ".$ouvrage." || ouvrage1 : ".$ouvrage1."|| ouvrage2 :" .$ouvrage2;
    ?>
Dev Tin
  • 157
  • 1
  • 9
  • 1
    `$login` is not defined in resume.php - it's defined in forme.php, which is a different script entirely. forme.php transitions to resume.php via a form action, but it doesn't carry variables across with it. If you want cross-page-transition variables to persist they need to be passed in the form or set in `$_SESSION`. – Mitya Feb 10 '21 at 19:09
  • You need to `$login = $_POST["login"];` in `resume.php` – Zak Feb 10 '21 at 19:10
  • @Zak thx for u answer but he always gives me the same error – Dev Tin Feb 10 '21 at 19:14

1 Answers1

1

Inside of formulaire.php You need to "carry" $login

There's a couple ways of doing this ..

One is with SESSIONS -- You can put session_start() at the TOP of
formulaire.php
and at the top of
resume.php
inside <?php tags IE

<?php
session_start();

In formulaire.php SET the session variable $_SESSION['login'] = $login;

In resume.php DEFINE $login as $login = $_SESSION['login'];


The other way is to set an input and "forward" it. Create the following input in formulaire.php:

 <input type="hidden" name="login" value="<?= $login ?>">

And call it in resume.php

$login = $_POST['login'];
Zak
  • 6,976
  • 2
  • 26
  • 48