Page 1 of 1

[SOLVED] SESSIONs Problem; simple

Posted: Wed Jun 25, 2008 10:48 am
by Twayne
:banghead:
Hi,
Learning PHP, XP Pro/SP2, Apache local server, PHP5.2.5. No relevant past similar language experience.
I'm having a devil of a time! I have two session variables and 3 pages I want to use them on. Of one particular pair, one works across all 3 pages, the other only across the first 2 pages; 3rd page doesn't "see" it.
With the exception that one is numeric and the other an e-mail address, after validation, I simply can NOT see why the e-mail address isn't availble to the 3rd page.

Structure: Captcha-like (but no image, just a few questions) page and e-mail address input/confirmation e-mail input.
Structure:
-- Page 1: Enter, data to use to validate human vs. robot etc.
-- Page 2: Success/error page and 3 links to one of 3 different forms upon success.
-- Page 3: One of the 3 available forms for the visitor input.
A quick 'pop-quiz' check here is to ask for 'age' and compare it to what was entered back on page 1.
The email address "$eml" isn't available on page 3; while age is.

'age' and 'eml' are entered on page 1, using identical '<input ... ' formats. 'age' is made available on page 3, but 'eml' is not available on page 3; somehow I'm screwing it up.

Here's the relevant code below. I've shown only what I think is relevant code; there IS validation in the form of 'FILTER_VALIDATE_EMAIL', which is "fixed" in this rev, though I'm fairly sure it has nothign to do with my issues. No validation is done on "age"; it's for later use.
I can post more complete code if it's deemed necessary:

Entry page:

Code: Select all

 
<?php
 # SessionPage1.php
# Original from: Dr. Herong Yang, http://www.herongyang.com/
# Written in PHP 5.2.5 on XP Pro SP2 & local Apache server
#
   session_start();
   $pw=mt_rand(x,y). mt_rand(x,y)*3; // random password generator
   $_SESSION['pw']=$pw;         // pw for use as access number below
      $_SESSION['age']=$age;        // OK; WORKING on check1.php
 $_SESSION['eml']=$eml; // OK ON check1.php, NOT OK; NOT WORKING on spca.php
      if (isset($_SESSION['count'])) {
      $count = $_SESSION['count'];
   } else {
      $count = 0;
   }
   $count++;
   $_SESSION['count'] = $count;
 
<form
Enter a valid e-mail address here:<br><input type=text name="eml">
...
 
Validate/congrats/offer links to 3 different forms:

Code: Select all

 
<?php
# check.php
   session_start();
    $pw = $_SESSION['pw'];      //  This was assigned in 1
    $age=$_SESSION['age'];
    $eml=$_SESSION['eml'];
   $count = $_SESSION['count'];
   $count++;
   $_SESSION['count'] = $count;
   #    ERROR SET
$error=0;
#
?> <meta name="robots" content="noindex, nofollow">
<?php
 
echo "eml is " . $_POST['eml']; // OK HERE; *NOT OK* ON spca.php
echo "Age is " . $_POST['age'];         // OK HERE; OK ON spca.php
 

One of the 3 possible forms linked to in above:

Code: Select all

 
<?php
session_start();
   
    $pw = $_SESSION['pw'];      //  This was assigned in 1
    $age=$_SESSION['age'];
    $eml=$_SESSION['eml'];
    $count = $_SESSION['count'];
   $count++;
   $_SESSION['count'] = $count;
#   ERROR SET
$error=0;
#
?> <meta name="robots" content="noindex, nofollow">
 <?php
  echo "eml is " . $eml;
echo "eml is " . $_POST['eml'];
?>
 
 


Thanks for reading; usually it's something simple or stupid I've done when it comes to this sort of thing but damned if I can figure it out!

Twayne

Re: SESSIONs Problem; simple

Posted: Wed Jun 25, 2008 11:05 am
by jayshields
Whatever you're trying to do looks pretty (over) complicated.

Not once do you assign a form submitted input to a session variable, and I don't know which page your form is submitting to.

I'm going to guess that your entry page provides a form which submits to your validate page and it's using the post method. In this case, you don't need any PHP code on the entry page. Now, on the validate page, you can grab the form inputs into the session variables by doing something like

Code: Select all

session_start();
$_SESSION['email'] = $_POST['eml'];
$_SESSION['age'] = $_POST['age'];
Then when you click some links or whatever on that same page (providing that they're local...) you can access those session variables using

Code: Select all

session_start();
echo $_SESSION['email'];
echo $_SESSION['age'];
Does that help you at all?

SOLVED Re: SESSIONs Problem; simple

Posted: Wed Jun 25, 2008 12:27 pm
by Twayne
SOLVED! Working as expected now. Turns out I just can't spill "eml" kor-rectumly!

Q: What's the best way for a newbie to ask a dumb question?
A: Ask those who know MORE than you do, in which case the answer will jump right out at you!

I will not ask this kind of question...I will not ask this kind of kwestshun...
I will not ask this kind of question...I will not ask this kind of kwestshun...
I will not ask this kind of question...I will not ask this kind of kwestshun...

Sorry for wasting the ether!

Twayne

Solved Re: SESSIONs Problem; simple

Posted: Wed Jun 25, 2008 12:38 pm
by Twayne
jayshields wrote:Whatever you're trying to do looks pretty (over) complicated.

Not once do you assign a form submitted input to a session variable, and I don't know which page your form is submitting to.

I'm going to guess that your entry page provides a form which submits to your validate page and it's using the post method. In this case, you don't need any PHP code on the entry page. Now, on the validate page, you can grab the form inputs into the session variables by doing something like

Code: Select all

session_start();
$_SESSION['email'] = $_POST['eml'];
$_SESSION['age'] = $_POST['age'];
Then when you click some links or whatever on that same page (providing that they're local...) you can access those session variables using

Code: Select all

session_start();
echo $_SESSION['email'];
echo $_SESSION['age'];
Does that help you at all?
============

The problem turns out to be a 'miss spelling'; got a finger in front of my eye tooth & couldn't see what I was typing. It was a typo; 'eml' for some reason doesn't equal 'elm" <g>. Duhh!
I do appreciate your taking the time to respond; your clarification was most helpful as a matter of fact.
I'll try to be much more accurate in my descriptions in the future: it made sense when I wrote it, but I can see why it's confusing to read now.

Regards,

Twayne

Re: [SOLVED] SESSIONs Problem; simple

Posted: Wed Jun 25, 2008 1:19 pm
by califdon
Don't feel bad. Compared with some of the questions we see here, yours was a jewel of clarity. It takes some experience with forums like this to become efficient at asking the right question and providing the needed information. And, as hard as it may be to believe, you are not the first programmer to misspell something and not catch it, even on the 50th re-reading. Feel welcome to come back here the next time you have a question.

Re: [SOLVED] SESSIONs Problem; simple

Posted: Wed Jun 25, 2008 5:32 pm
by jayshields
Nicely put califdon, and I'm glad it was of some help Twayne!

Re: [SOLVED] SESSIONs Problem; simple

Posted: Wed Jun 25, 2008 8:49 pm
by Twayne
califdon wrote:Don't feel bad. Compared with some of the questions we see here, yours was a jewel of clarity. It takes some experience with forums like this to become efficient at asking the right question and providing the needed information. And, as hard as it may be to believe, you are not the first programmer to misspell something and not catch it, even on the 50th re-reading. Feel welcome to come back here the next time you have a question.
Thanks; appreciate the encouragement. I'm new enough I often don't even know for sure what phraseology to use for some of my questions. The posts on this forum make for some good reading when I have the time; very useful.
I'll be back, I'm sure.

Thanks again,

Twayne