Current location: Hot Scripts Forums » Programming Languages » PHP » Multiple Page PHP Registration form


Multiple Page PHP Registration form

Reply
  #1 (permalink)  
Old 06-21-06, 08:26 AM
losse losse is offline
Newbie Coder
 
Join Date: Jun 2006
Location: Barrie, Ontario, Canada
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Multiple Page PHP Registration form

Hi gang... this is my first post on this forum... Nice to meet you all!!!

I'm in a bit of a conundrum... I'm trying to create a multiple page registration form wher a user inputs personal info and product/service info over 3 pages.

There is a fourth page that basically sums up the fields entered in the previous 3 pages to make sure the user didn't make any mistakes and that everything is peachy keen.

Originally I had a SESSION START on all the pages with:

-An INSERT script on page 1
-AN UPDATE script on page 2 (that looked up the user ID from the SESSION START in page 1)
-An UPDATE script on page three.

My issue is that on page 4, if they do have to make a change and have to go back to say page 1, that will create a conflict with the INSERT script...

So my question is, how can I "hold" the variables that the user inputs up until they submit the data from the confirmation page on page 4? That way, if they do go back and change stuff, it won't touch the database until they're happy with it and hit SUBMIT.

Thanks
Reply With Quote
  #2 (permalink)  
Old 06-21-06, 08:51 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
If you already have a session, why not store the values in session variables?

Forwarding data between multi-page forms is usually done using hidden fields. Here is a link, which also contains some code to automate this - http://www.zend.com/zend/spotlight/c...lery-wade7.php
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #3 (permalink)  
Old 06-21-06, 10:07 AM
losse losse is offline
Newbie Coder
 
Join Date: Jun 2006
Location: Barrie, Ontario, Canada
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
Aren't hidden fields kinda risky when it comes to security? I considered that before but think that session variables might be a bit better.

do you have a sample code for session variable? I'd like to consider that option.

Thakns for your reply
Reply With Quote
  #4 (permalink)  
Old 06-22-06, 02:06 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
it depends on what you store in them off course. i myself never use em, except for file upload.
here's an example of how to use the sessions:
page 1 (just an example)
PHP Code:

<?php

if($_POST['submit']){ // checks if the form is filled in and submitted
  
if(!empty($_POST['username']) && !empty($_POST['password'])){
    
session_start();
    
$_SESSION['username'] = $_POST['username']; // if you want to do something like this, make sure you check the contents of the username var before sending it to the session var
    
$_SESSION['password'] = md5($_POST['password']); // same here
  
}else{
    echo 
"Some fields were left blank";
  }
}
?>
<html>
<body>
<form method="post">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
so when the user submits the form, the data will be stored in the session vars. to retrieve the info of the sessions on page 4:
PHP Code:

session_start();

$sql "INSERT INTO table SET username='".$_SESSION['username']."', password='".$_SESSION['password']."'"
when you want to delete the values in the session (when you send a user back to one of the previous pages, use:
PHP Code:

session_sart();

session_unregister('username'); 
Hope this helps a little bit
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #5 (permalink)  
Old 06-23-06, 02:09 PM
losse losse is offline
Newbie Coder
 
Join Date: Jun 2006
Location: Barrie, Ontario, Canada
Posts: 65
Thanks: 0
Thanked 0 Times in 0 Posts
UnrealEd
Thanks for this reply... i'll give it a shot...

I'm just a little unclear about this

PHP Code:

session_sart(); 

session_unregister('username'); 
Ideally I would like to assume that there is a chance the user would go back and edit some fields...

So would I put that snippet on every page? in it's on <php ?> tag at the top of all 4 registration pages?

Thanks - funny avatar by the way!!
Reply With Quote
  #6 (permalink)  
Old 06-24-06, 02:07 PM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
correct: the session_unregister needs to be used when a user go back to a page to fill in some different contents.

i think it's best to add some code at the beginning of every file (where the user can fill in the data), that will check whether the user has allready visited that page. it could look like this:
PHP Code:

session_start();

if(isset(
$_SESSION['some_field_that_has_to_be_submitted_on_this_page'])){
 
session_unregister('some_field_that_has_to_be_submitted_on_this_page');

so if there's a field that needs to be filled in, named 'username', you have to replace 'some_field_that_has_to_be_submitted_on_this_page' by 'username'. and so on for every page

Greetz,
UnrealEd
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
  #7 (permalink)  
Old 06-24-06, 10:33 PM
prettypretty's Avatar
prettypretty prettypretty is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Wink Best way out

Just declare another session var:
$_SESSION['ifsubmit']=0 (0 is the default value)

Once the info is submited, $_SESSION['ifsubmit']=1 (means you can not do it twice)
If viewers return to the previous pages and edit some fields, check the $_SESSION['ifsubmit'] value first when they submit at the final page for the second time. If $_SESSION['ifsubmit']==1, echo "You have already submited your info. Please login to edit your profile. Thanks."

Hope that meets your requirement.
__________________
try to make things pretty pretty...
Jeans Lover Gallery collects all kinds of jeans pictures: www.hiya.hk/jeans/

Last edited by prettypretty; 06-24-06 at 10:37 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-24-05 11:09 PM
question about updating a page or database for an, php and mysql updating mikewooten PHP 1 02-12-04 12:11 AM
E-Mail form / Send code on one page perleo PHP 4 02-11-04 01:16 AM


All times are GMT -5. The time now is 07:17 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.