473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Trouble With Sessions

I have a form that will be preserving form data prior to processing
the form data. Upon clicking a certain submit button you will go to
another PHP script that will contain the following code:

if (strcmp(strtolower($_POST['submit']), 'apply') != 0) { // GO BACK
TO grad_application with $_SESSION
session_start();
if (sizeof($_POST) > 0) $_SESSION['post'] = $_POST;
if (sizeof($_GET) > 0) $_SESSION['get'] = $_GET;
header("Location: http://$SERVER_NAME${devpath}grad_application.php?"
.. Session_Name() . '=' . Session_Id());
}

Upon redirection back to the original PHP form script I will include
an "HTML" file (its extension is HTML but it's actually PHP) that
should prepopulate the form fields with the data from $_SESSION. At
the top of my page I have:

session_start();

However, while I see the PHPSESSID in my query string I do not see any
of my form elements populated. This is how I am parsing $_SESSION in
the "HTML" file:

/*----------------------------------------------------------------------------------------------
Unclear as to how $_POST and $_GET vars are set, so as a backup, save
them here in macros.inc
------------------------------------------------------------------------------------------------*/
foreach ($_POST as $key => $val) {
if (!isset(${$key})) ${$key} = $val;
}

foreach ($_GET as $key => $val) {
if (!isset(${$key})) ${$key} = $val;
}

if (preg_match('/grad_application\.php/i', $REQUEST_URI) &&
isset($_SESSION['post'])) {
foreach ($_SESSION['post'] as $key => $val) {
$blah .= "key = $key and val = $val<P>\n";
if (!isset(${$key})) ${$key} = $val;
}
}

if (preg_match('/grad_application\.php/i', $REQUEST_URI) &&
isset($_SESSION['get'])) {
foreach ($_SESSION['get'] as $key => $val) {
if (!isset(${$key})) ${$key} = $val;
}
}

//---END OF FORM VAR DYNAMIC SETTING
BLOCK------------------------------------------------------

This was all based on php.net information on sessions at:
http://us4.php.net/manual/en/function.session-start.php

and at
http://us4.php.net/manual/en/printw....predefined.php

I've never had any success with sessions to be honest. Maybe I'm
approaching this whole thing wrong. Bottom line is that I want to
produce a form that has a button that will produce more form elements
upon click while retaining everything you typed so far.

Phil
Jul 17 '05 #1
2 2952
"Phil Powell" <so*****@erols.com> wrote in message
news:1c**************************@posting.google.c om...
I have a form that will be preserving form data prior to processing
the form data. Upon clicking a certain submit button you will go to
another PHP script that will contain the following code:

8< SNIP! >8

I've never had any success with sessions to be honest. Maybe I'm
approaching this whole thing wrong. Bottom line is that I want to
produce a form that has a button that will produce more form elements
upon click while retaining everything you typed so far.


Phew!!! Glad you got to the original problem or I was going to pass on this
one.

Are the form elements similar because maybe you should use an array of
elements; i.e.

<input name="name[0]" type="text" value="<?=$_POST['name'][0]?>">
<input name="name[1]" type="text" value="<?=$_POST['name'][1]?>">

And then when they want more you can just add some more and because you're
setting the initial values of these input fields to the same as what's
contained in the $_POST array you don't have to worry about storing the
values outside the web page.

Sessions do work very well but they're not always the easiest solution to
problems.

Paulus
Jul 17 '05 #2
Thanx but that would've failed. upon clicking the button you are
redirected from grad_application.php to grad_application_redirect.php
only to return BACK to grad_application.php with retained vars or
doing processing depending on which submit button you clicked.

I got it solved, I had to move $_SESSION to the function inside a
class object instance in a library elsewhere.

Phil

"Paulus Magnus" <pa***********@loves-spam.com> wrote in message news:<bl**********@titan.btinternet.com>...
"Phil Powell" <so*****@erols.com> wrote in message
news:1c**************************@posting.google.c om...
I have a form that will be preserving form data prior to processing
the form data. Upon clicking a certain submit button you will go to
another PHP script that will contain the following code:

8< SNIP! >8

I've never had any success with sessions to be honest. Maybe I'm
approaching this whole thing wrong. Bottom line is that I want to
produce a form that has a button that will produce more form elements
upon click while retaining everything you typed so far.


Phew!!! Glad you got to the original problem or I was going to pass on this
one.

Are the form elements similar because maybe you should use an array of
elements; i.e.

<input name="name[0]" type="text" value="<?=$_POST['name'][0]?>">
<input name="name[1]" type="text" value="<?=$_POST['name'][1]?>">

And then when they want more you can just add some more and because you're
setting the initial values of these input fields to the same as what's
contained in the $_POST array you don't have to worry about storing the
values outside the web page.

Sessions do work very well but they're not always the easiest solution to
problems.

Paulus

Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Avinash Korwarkar | last post by:
Hi Guys, I am using sessions to store the login name and then retrieve it on every page. Here are the details of the php settings. 1) I have PHP 4.2.2 installed on a Apache 1.3.27 server. 2)...
0
by: Mountain Man | last post by:
Hi, I'm having trouble with sessions. Text fields from a form aren't getting updated when the form is resubmitted. On the other hand, my radio buttons are updated every time. Many thanks to...
9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
3
by: LMachado1 | last post by:
I just started with php and I'm trying to make a simple interface as follows: - user is asked to input an integers, for example: how many students do you want to enter? - user is then shown a...
0
by: David Staschover | last post by:
I'm trying to set up sessions in perl. The session is initialized fine in session1.cgi In session2.cgi, the correct session id is returned from the cookie, but when I initialize the session, a...
3
by: BravesCharm | last post by:
BravesCharm Dec 7, 10:57 am show options Newsgroups: microsoft.public.dotnet.distributed_apps From: "BravesCharm" <mastrauc...@gmail.com> Date: 7 Dec 2004 10:57:40 -0800 Local: Tues, Dec...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
14
by: aroraamit81 | last post by:
Hi, I am facing a trouble. I have some Session variables in my code and somehow my session variables are getting mixed up with other users. For example User A has access to 10 companies and...
4
by: DavidPr | last post by:
I'm using Jpmaster77 a.k.a. The Grandmaster of C++ 's register/login system and I'm having a problem with the session being dropped when I try to submit a form to the same page. A user has to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.