SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help newbie please... how to use session in my form???

    how to use session in my form???

    hi,i have a simple form to process and store user input into database.
    first,the user need to fill in their particulars.
    then they can press submit top review the data.They can press 'modify' to back to the previous page to modify.
    Else,they can save the data with 'save' button.

    my problem is....

    how can i display the pre entered data when the user press 'modify' button?
    i know there's a way by using input type ="hidden"...
    however,i wish to make it using session...

    can anyone please share your knowledge?


    PHP Code:
    <?php
     
    if (($_SERVER['REQUEST_METHOD'] != 'POST'))||(($_POST['modify'])){
     
    ?>
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'?>">
    name :<input type=text"name="name"><br>
    phone number:<input type="text" name="phone"><br>
    gender: <input type="radio" name="gender" value="1">Male
            <input type="radio" name="gender" value="2">Female<br>
    address: <input type="textarea" name="address"></textarea><br>
    <input type="submit" value="submit" name="submit">
    </form>
    <?php 
    }


    ////////PREVIEWTHE ENTRY
    if(isset($_POST['submit'])){
    echo 
    "<form method='post' action='save.php'>";
    echo 
    "name : $_POST['name']<br>";
    echo 
    "phone numver : $_POST['phone']<br>";
    echo 
    "gender : $_POST['gender']<br>";
    echo 
    "address: $_POST['address']<br>";
    echo 
    "<input type='button' value='modify' name='modify'><br>";
    echo 
    "<input type='submit' value='submit' name='save'>";
    echo 
    "</form>";
    }
    ?>
    Last edited by cathie; Dec 17, 2006 at 04:40.

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmn, I think you'd first need your save button to read an update code for your database and your modify button to read a history code to go back.

    Other than that, you use a session by doing: $_SESSION['id']; etc. a good example of these are login's with sessions. That way you give the user access to a members area where their id/username/email etc. anything to identify them in the database to echo only their information to modify.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2006
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aymie Jordaine,

    hi,thanks for your reply..

    i tried to add code eg onclick="javascript:history.back(-1)" to my modify button and put the form action to save.php
    PHP Code:
    ////////PREVIEWTHE ENTRY
    if(isset($_POST['submit'])){
    echo 
    "<form method='post' action='save.php'>";
    echo 
    "name : $_POST['name']<br>";
    echo 
    "phone numver : $_POST['phone']<br>";
    echo 
    "gender : $_POST['gender']<br>";
    echo 
    "address: $_POST['address']<br>";
    echo 
    "<input type='button' value='modify' name='modify'><br>";
    echo 
    "<input type='submit' value='submit' name='save'>";
    echo 
    "</form>";
    }
    ?> 


    however, the pre entered data is not shown when modify is clicked.

    actually how we assign value to session so it can be accessed globally?

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2005
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually how we assign value to session so it can be accessed globally?
    To use a session you would have to call
    Code:
    session_start();
    at the start of the all the php pages where you want to access the sessions. You can call and store values to session like the following respectively:

    Code:
    $_SESSION['name'] = "A String Value"; // or here $_POST['input_field_name']
    Code:
    echo $_SESSION['name'];
    In the value="" of the input field do something like

    Code:
    <input value="<?php if (isset($_SESSION['name'])) { echo $_SESSION['name'] ; } ?>" name="... so on.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •