Closed Thread Icon

Topic awaiting preservation: PHP Session ... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12924" title="Pages that link to Topic awaiting preservation: PHP Session ... (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP Session ... <span class="small">(Page 1 of 1)</span>\

 
shalvi
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2003

posted posted 10-09-2003 09:21

Hello,
I want to pass email and password value from Form1 to Form2 with session so I am using
<input type="hidden" name="<?=session_name() ?>" value="<?=session_id() ?>">

and in the Form2 I am just simply putting the value..

$sql = "INSERT INTO tutor ( email, pswd ) VALUES ( '$email', '$password' )";

what is wrong I am doing ?
will you suggest me please?

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 10-09-2003 10:40

shalvi: I suspect you are going to have to give us more information as what you have given us didn't make any sense.

If you are using a session then you don't need to pass the data between forms using a hidden form as the point of sessions is that they hold information like this so it can be used across pages.

I'm not sure where the session_name() and session_id() fucntions come in or how the 2 bits of code are connected.

If you could expand on your question(s) we might be able to help you better.

[edit: see also:

:FAQ: Basic PHP Session Tutorial

as this is a good introduction]

___________________
Emps

The Emperor dot org

Rhino
Bipolar (III) Inmate

From: New Jersey, USA
Insane since: Jul 2003

posted posted 10-09-2003 10:54

Shavi,

I don't understand why you are storing the values in Form elements if they are already in Session. Anyway, to get the values from Session you should use the following syntax

$email = $_SESSION["email"];
$password = $_SESSION["password"];

If you want to get the values submitted from a Form using POST method you would use the following syntax

$email = $_POST["email"];
$password = $_POST["password"];

if using GET method

$email = $_GET["email"];
$password = $_GET["password"];


Hope this helps

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 10-09-2003 13:51

Uh, as far as I can tell he's not passing anything by a hidden except for the session ID so it can be continued on the next page. This is an accepted way of handling sessions in PHP. You can pass the session ID and session name by POST, GET or cookie. I prefer the cookie method personally.

shalvi
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2003

posted posted 10-09-2003 14:14

hello,
thanx for your help...now my code appears below...still i can't get the value of email and password in page2.php....
maybe there's a silly mistake i am doing...


//page1.php


<INPUT class=text id=email maxLength=100 size=37 name=email>
<input type="password" class="text" name="password" id="password" size="37" maxlength="100" >

<?php
session_start();
$_SESSION['email'] = $email;//email is the form value
$_SESSION['password'] = $password;//password is the form value
?>

//page2.php

<?php
session_start();
$email = $_SESSION['email'];
$password = $_SESSION['password'];
$sql = "INSERT INTO tutor ( email, pswd ) VALUES ( '$email', '$password' )";



Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 10-09-2003 14:38

Well for one thing you don't have a submit button your your form, so it can't do anything with it, plus the fact you're trying to load values out of the $_POST array on the same page as putting them into it...that won't work. On page two where you use $_SESSION is where you should be using $_POST

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 10-09-2003 14:46

Skaarjj: Good point - it was too early and the post and me weren't making sense.

That said you could still get into problems doing things like that.

shalvi: Could I refer you to the manual:
http://www.php.net/manual/en/ref.session.php

Basically Skaarjj's answer is right - you don't need to start the session on page1 and you get the info through the POST (how you do that depends on the version of PHP you are using).

___________________
Emps

The Emperor dot org

shalvi
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2003

posted posted 10-09-2003 15:48

well what i am trying to do is....get the email address and password in Form1(page1.php) then it goes to the Form2 ..and there user will provide user details like name,address,phone no etc..then in the Form2 after submission page3.php will add the information in the database....

<FORM name=registrationform //This is submission of Form1
onsubmit="return validateForm(this)"
action="page2.php "method=post>

then page2.php will get user details and...

<FORM name=registrationform
onsubmit="return validateForm(this)"
action=page3.php method=post>

so i need to carry that email and password from page1.php to page3.php....

as i am a newbie in PHP may be this a silly mistake...but can't make it work

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 10-09-2003 17:53

n/m

I misread that last post....


[This message has been edited by DL-44 (edited 10-09-2003).]

Rhino
Bipolar (III) Inmate

From: New Jersey, USA
Insane since: Jul 2003

posted posted 10-09-2003 18:38

First you need to get the values that have been submitted. As Skaarjj had written, you should be using $_POST to retrieve the values on page2.php.

For example:

$password = $_POST["password"];
$email = $_POST["email"];

This is what should be used to retrieve the values that have been submitted. You can then put those values into hidden fields if you choose or store them into session.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 10-09-2003 18:42

I Think you are confusing how server-side PHP works as opposed to client side.

This:

<INPUT class=text id=email maxLength=100 size=37 name=email>
<input type="password" class="text" name="password" id="password" size="37" maxlength="100" >

<?php
session_start();
$_SESSION['email'] = $email;//email is the form value
$_SESSION['password'] = $password;//password is the form value
?>

Will not get the form values into your session variables. All PHP is done before the HTML gets to the browser. In page 1 all you need is the raw form, no PHP.

In Page 2 you want to add the variables to the session and you want to get those variables from 1 of 3 arrays $_POST, $_GET or $_REQUEST (which is $_GET and $_POST combined)

so in page 2 you want

$_SESSION['email'] = $_REQUEST['email'];
$_SESSION['password'] = $_REQUEST['password'];


Now in page 3 you will be able to access $_SESSION['email'] and $_SESSION['password']

In this case you really don't need sessions, a couple of hidden input fields would work fine. Especially since you are creating a temporary form on page 2 where you will need to put the values from page 1.




.:[ Never resist a perfect moment ]:.

shalvi
Nervous Wreck (II) Inmate

From:
Insane since: Oct 2003

posted posted 10-09-2003 20:33

thanx guys.. it's working at last....thank you all

« BackwardsOnwards »

Show Forum Drop Down Menu