Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help with Sessions

Posted on 2004-04-14
5
Medium Priority
?
223 Views
Last Modified: 2008-03-06
I have a web site that that has 4 pages to get information from the user.  The problem I am having I was trying to use sessions to keep the data entered on pages 1-4 then on page 5 after the user reviews their information they would submit it and it would post to the mysql database.  I can pass session information to the next page but can't keep it going to the other pages.  Here is an example.

page 1

Enter First Name:

Page 2

Enter Last Name:

Page 3

Enter Address:

Page 4

Enter State:

Page 5

Review the data built in the session array then submit and enter into database.

I know how to submit the data to the database but I can't seem to build the array even though I'm using session_start(); on every page.

I am looking for exact information here as I am knew to PHP and have purchased 3 PHP books so far yet nope give me an example to passing information like I am wanting.

Using PHP 4.3.5.5 on a windows platform but once this proto type is complete will be moving to a unix server.

Thanks
0
Comment
Question by:Uzaree
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Expert Comment

by:bjai
ID: 10830338
in order for session to be carried to 'other' pages you need to call session_start() on those other pages also

e.g. after page 5 you get redirect to page '6', that page 6 need to call session start() also. In case after page 5 you are doing a form submit to e.g. process_form.php the file needs to call session_start(), then within this process_form.php you can do whatever is required (in your case insert/update data to database) then can you only redirect to other pages without session_start()

To summarize:
Page 1 (session_start() required)
Page 2 (session_start() required)
Page 3 (session_start() required)
Page 4 (session_start() required)
Page 5 (session_start() required)
[form submit to process_form.php (session_start() required)]
Redirect to Page 6
0
 
LVL 6

Expert Comment

by:jkna_gunn
ID: 10831466
how are you adding and reading data from the session?
0
 

Author Comment

by:Uzaree
ID: 10835885
I do have session_start() on every page but here is teh code from all 3 pages that I was trying to do tests with.

Page login.htm

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<table width="140" border="1">
  <tr>
    <td>
      <form name="login" method="post" action="login.php">
      Login: <input type="text" name="name">
      <br>
    Password: <input type="text" name="textfield2">
        <input type="submit" name="submit" value="Login">
      </form>
    </td>
  </tr>
</table>
</body>
</html>

page login.php

<?php
session_start();
header("Cache-control: private");

$name = $_POST['name'];

$_session['name']=$name;

?>

Welcome <? echo $_session['name'];?>

<a href="login1.php">Login <a/>


Page login1.php

<?php
session_start();
header("Cache-control: private");

?>

Welcome <? echo $_session['name'];?>

When I get to the last page I can't seem to get the $_session['name'] to display anything
My luck its going to be something really easy that I'm missing
0
 
LVL 2

Accepted Solution

by:
Fataqui earned 600 total points
ID: 10837731
Hi


You problem is very simple..... ( naming conversion ) -> lower case invalid

$_POST, $_REQUEST, $_GET, $_SERVER, $_ENV, $GLOBALS, $_SESSION, $_FILES, $_COOKIE

The above are all members of the AUTO GLOBALS -> "!!!predefined and reserved!!!"

You are using -> $_session

Which is not valid, and will not add any assigned value to the session array....

Always use what I listed above.....

So to correct your problem.....

change all of these..............

$_session['name'] = '?';

change to..........

$_SESSION['name'] = '?';


C, ya....

Fataqui

PS: To help you understand what I am talking about, go here...

http://us2.php.net/manual/en/language.variables.predefined.php#language.variables.superglobals




0
 

Author Comment

by:Uzaree
ID: 10844856
Thanks Fatagui that fixed me up just right.  I didn't notice the case change on the superglobals and I haven't read anything about it but that explains alot now.  Once again thanks.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question