How to retain information from a form

Hey guys!

I am trying to figure out how to retain the form information when a page refreshes but it doesn’t seem to work. I have set the form action towards another page though and use the following code:

<!DOCTYPE html>
<html>
<head>
   <title>  </title>
   <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

</body>
</html>

<?php

session_start();

   if(isset($_SESSION['u_uid'])) {
      header("Location: index.php?signup=mustlogoutfirst");
      exit();
   } else {
      include 'includes/dbh.php';
      include_once 'header.php';
}

?>

   <section class="main-container">
    <div class="main-wrapper">
    
      <h2>Signup</h2>
      <form class="signup-form" action="includes/signup2.php" method="POST">
         <label>Firstname</label>
         <br></br>
         <input type="text" name="first" placeholder="First Name" value="<?php if(isset($_SESSION['u_first'])) { echo $_SESSION['u_first'];}?>">
         <label>Lastname</label>
         <br></br>
         <input type="text" name="last" placeholder="Last Name">
         <label>E-Mail</label>
         <br></br>
         <input type="text" name="email" placeholder="Email">
         <label>Username</label>
         <br></br>
         <input type="text" name="uid" placeholder="User ID">
         <label>Password</label>
         <br></br>
         <input type="password" name="pwd" placeholder="Password">
         <label>Basic Subscription Plan</label>
         <br></br>
         <select name="freelesson">
            <option value="Primer Level">Primer Level: Free</option>
         </select>
         <br></br>
          <label>Premium Subscription Plan 1</label>
          <br></br>
         <select name="subscriptionplan">
            <option value="">Choose Subscription Plan 1</option>
            <option value="None">None</option>
            <option value="Level 1">Level 1</option>
            <option value="Level 2">Level 2</option>
            <option value="Level 3">Level 3</option>
         </select>
         <br></br>
         
         <button type="submit" name="submit">Sign up</button>
      </form>
     </div>
  </section>

Should I use session or post for the value output?

As previously mentioned, try error_reporting(), etc at the top of each page. When the script is clear of all the errors and warnings, post your revised script… preferably formatted to make it easier for users to understand.

1 Like

That should be a clue…

But I can only get this to work if the information is sent to the same page. I just can’t get it to work when I have forwarded action=“another.php” for example…

Why not? What have you tried? What happened when you tried that?

I tried it but it didn’t show the first name or last name but it did work when I set action = “”

Again, we can’t help you if you don’t post any code.

3 Likes

Show us the code for that page, as well as the code you have shown. There’s no reason for it not to work, it’s just spotting the mistake / typo.

1 Like

Ok… will get to it ASAP

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.