retain form data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zhtway
    New Member
    • Dec 2009
    • 1

    retain form data

    Hi,

    I am very very new to web programming and I want to retain data once the form is submitted. I tried other says but no luck. Could someone point it out for me please?

    Code:
    <?php
    session_start(); // Start the session where the code will be stored.
    ?>
    
    <html>
    
    <head>
    <title>Securimage Test Form</title>
    </head>
    
    <body>
    
    <?php
    if (empty($_POST)) { ?>
    
    <form method="POST" >
    <strong>Name:</Strong><br />
    <input id="text" name="usname" />
    Code:<br />
    <input type="text" name="code" size="12" /><br /><br />
    
    <input type="submit" value="Submit Form" />
    </form>
    
    <?php
    } else { //form is posted
    echo "<center>Sorry, the code you entered was invalid. <a href=\"javascript:history.go(-1)\">Go back</a> to try again.</center>";
    if (isset($_POST[username])) return $_POST[username];
    }
    ?>
    </body>
    </html>
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    Instead of printing only an error message, also print the form and make use of the value attribute of the <input> element. You'll want to set it to the data inside of the $_POST array.

    Comment

    Working...