Web Analytics Made Easy -
StatCounter go back previous page - CodingForum

Announcement

Collapse
No announcement yet.

go back previous page

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • go back previous page

    How am i going to code the php page to be able to go back a previous page.
    For example, if i have a employee.php where the user have to enter the name, address, phone, date of birth and etc. After the user clicked the submit button, the newemployee.php will checked if the user entered all the data before a new employee details will be entered in the database.
    If the user does not enter the date of birth, i want to go back to the employee.php page which display the previously uncompleted entered data.

  • #2
    You need to store the form data in a session, and to redirect the user you can send a HTTP header:

    PHP Code:
    header("Location: http://www.example.com/employee.php?" SID); 
    Of course you need to replace the URL with the one you're currently using, and point to the right file. After the user get's redirected to the employee.php page, you check if form data is stored in the session and if so, write the values into the form fields.
    De gustibus non est disputandum.

    Comment


    • #3
      You may also wish to use Javascript to 'validate' the form before sending it to the php page.

      However, you will not be able to check things against a database necessarily. For example, if you have a username field and want to make sure that it hasn't been taken already, you won't be able to do this using Javascript (unless you query the database for this information first, and transpose it into a Javascript array of course... but then you're giving the client priveledged information...).

      If you are merely testing whether fields have been filled in or have a particular format (ie. email address or dates), this is something that can be done with Javascript.

      Here are some links that may help in this regard:
      Take your web pages to the next level with interactive JavaScript elements. Find tutorials, how-tos, sample scripts, and more to help you learn to write your own JavaScript code.

      Founded in 1997, DEVShed is the perfect place for web developers to learn, share their work, and build upon the ideas of others.


      Hope that helps,
      Sadiq.

      Comment


      • #4
        If the user does not enter the date of birth, you can have it print a meta refresh to the page using the if...else statements.
        ~Designer's Toolz~

        Comment


        • #5
          PHP Code:
          <?php
          if(empty($dateofbirth))
          {
          print  
          "<meta http-equiv=\"Refresh\" content=\"1;URLput the url to the previous page here with no spaces.html\">";
          }
          ?>
          ~Designer's Toolz~

          Comment

          Working...
          X