Forms that remember previous input

Discussion in 'PHP' started by procaelio, Mar 14, 2007.

  1. #1
    I have a MySQL - Apache - PHP setup. I have a web page with a form asking for various input.

    I want to introduce php into my web page that will take information supplied by the user, send it to a database and store it so that the next time the user logs into the page, all his previous input is still there. Of course the web page will be secured for a single user.

    Can anyone point me in the right direction as far as what general areas of PHP and database development I need to look into in order to accomplish this.

    Thanks for any replies.
     
    procaelio, Mar 14, 2007 IP
  2. jitesh

    jitesh Peon

    Messages:
    81
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This is so simple with persistent cookie.

    Let me explain.

    Suppose you want to save firstname and lastname for 10 days then write a script

    setcookie('firstname','john',time()+3600*24*10);
    setcookie('lastname','de',time()+3600*24*10);

    Now later when you come back you can access values from $_COOKIE['firstname'] and $_COOKIE['lastname'];
     
    jitesh, Mar 14, 2007 IP
  3. Rub3X

    Rub3X Well-Known Member

    Messages:
    1,902
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    135
    #3
    Expanding on the above, you'll want to use some sort of unique hash in the cookie. That way you know which data to pull from the database - depending on which hash is in the cookie.
     
    Rub3X, Mar 14, 2007 IP
  4. mikemotorcade

    mikemotorcade Peon

    Messages:
    645
    Likes Received:
    49
    Best Answers:
    0
    Trophy Points:
    0
    #4
    well, if the user has to log in, you could just run a query like;
    SELECT * FROM table WHERE userid = $currentuserid LIMIT 0,1
    Code (markup):
    then just echo the values of the row into the input boxes
    <input type=text" name="whatever" value="<?php echo $row['field']; ?>">
    HTML:
     
    mikemotorcade, Mar 16, 2007 IP
  5. kobra

    kobra Member

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    The best way to do what you ask and in my opinion the best way to validate forms is to store all the form data into a php Session that way if the user decide to refresh the page in the middle of the process you'd safe and no double input would be inserted into the database.
     
    kobra, Mar 16, 2007 IP