473,386 Members | 1,610 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.

Session variable

I'm going nuts over this one. Perhaps this is kludgy, but it has worked for
me before.

When I give the user a form, say AAA.php that has a few fields on it, and he
has to fill it out, I check for validity. If I find an error, I created a
session variable like:

$_SESSION['AnError'] = "Description of the error";

I then call the form again with

header("Location: ThisForm.php");

In the <body> area I have

<?php if (isset($_SESSION['AnError'])) echo $_SESSION['AnError']; ?>

Doing thing like this has worked before. Now, for a particular form when I
try it, it doesn't display. I tested it further with

<?php echo "Error: . $_SESSION['AnError']; ?>

and only the "Error: " displayed. This told me that the session variable
was not set. However, if I put echos in the code immediately after it gets
set, then it echos and prints further that the headers have already been set
(BTW, what does that mean?). So, I know that it is being set, it is not
being unset anywhere, yet it isn't set when the form redisplays.

I have been banging my head against the wall for hours now. Anyone have any
ideas?

Shelly
Jul 17 '05 #1
2 1272

"Shelly" <sh************@asap-consult.com> wrote in message
news:MM********************@comcast.com...
I'm going nuts over this one. Perhaps this is kludgy, but it has worked
for me before.

When I give the user a form, say AAA.php that has a few fields on it, and
he has to fill it out, I check for validity. If I find an error, I
created a session variable like:

$_SESSION['AnError'] = "Description of the error";

I then call the form again with

header("Location: ThisForm.php");

In the <body> area I have

<?php if (isset($_SESSION['AnError'])) echo $_SESSION['AnError']; ?>

Doing thing like this has worked before. Now, for a particular form when
I try it, it doesn't display. I tested it further with

<?php echo "Error: . $_SESSION['AnError']; ?>

and only the "Error: " displayed. This told me that the session variable
was not set. However, if I put echos in the code immediately after it
gets set, then it echos and prints further that the headers have already
been set (BTW, what does that mean?). So, I know that it is being set, it
is not being unset anywhere, yet it isn't set when the form redisplays.

I have been banging my head against the wall for hours now. Anyone have
any ideas?

Shelly


Well, it works now. I am not sure why, but here is what I did. After I had
echoed the variable in the <body> area, I had unset it since I didn't want
to keep it around after the display. What I changed was that I removed
that unset and placed it where I successfully started to upload the file
that I wanted. In other words, where there were no client side errors.

Could someone explain to me why that works? Is it that it does the page
twice on redisplay, getting the variable on the first time but then it
doesn't have it on the second pass (after the original unset)?

Shelly
Jul 17 '05 #2
On Sat, 09 Jul 2005 15:52:52 -0400, Shelly wrote:
and only the "Error: " displayed. This told me that the session variable
was not set. However, if I put echos in the code immediately after it gets
set, then it echos and prints further that the headers have already been set
(BTW, what does that mean?). So, I know that it is being set, it is not
being unset anywhere, yet it isn't set when the form redisplays.

I have been banging my head against the wall for hours now. Anyone have any
ideas?


Yes. Probably, your web server has specified the nature of the error in
the log file. My server (Apache 2.0.53) does it like this:
[client 127.0.0.1] PHP Parse error: parse error, unexpected '{' in
/home/mgogala/work/DBA/security.php on line 25, referer:
http://localhost/dba/main_menu.html

If I am not mistaken, you haven't started the session, in the first place.
This is how things should look:

<?php
require_once ('config.php');
session_start();
$DSN = $_SESSION['DSN'];
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$ADODB_COUNTRECS = true; $db = NewADOConnection("oci8");
$usr = $_GET['user'];
$USRINFO = 'select USERNAME,
ACCOUNT_STATUS STATUS,
EXPIRY_DATE EXPIRES,
DEFAULT_TABLESPACE "DFLT. TBLSPCE",
TEMPORARY_TABLESPACE "TEMP. TBLSPCE",
CREATED,PROFILE,
........

After invoking the session_start() function, I can read my connect
information into the $DSN variable. Last, saying that "this has
worked before" makes no sense whatsoever and is probably the single
most irritating thing you can say to a support person. You either have
to explain before what exact event was it working or get the support
person to start believing in ghosts which are haunting your code. If
the support person has geeky sense of humor, it can be rather unpleasant
proposition.

--
http://www.mgogala.com

Jul 17 '05 #3

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

Similar topics

11
by: doltharz | last post by:
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean newsgroup article), i always use Option...
1
by: Ann Leland | last post by:
I have been using session variables to pass a user name from one ASP page to another inside framesets for 9 months and it stopped working this week. I have made no code changes but there was a...
2
by: Eric | last post by:
Hi, I've a problem with trying to retrieve a session variable in an include file. Basically, the main asp creates a session variable: <% Session("var1") = "Hello" %> And then when I click...
4
by: VB Programmer | last post by:
If I have a variable I want to share in my application what is the difference between just declaring a variable (Dim strMyVar as String) and using a session variable (Session("strMyVar"))? When...
9
by: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example...
9
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
4
by: T Ralya | last post by:
I am told that ASP.NET controls the session ID and session variables, but that does not fit my symptoms. I am posting here as directed. I'm hoping that someone can at least recommend something to...
3
by: Alan Wang | last post by:
Hi there, Once my application gets complicated and complicated. I found it's really hard to keep track of Session value I am using in my asp.net application. I am just wondering if anyone have...
4
by: Don Miller | last post by:
I am using a Session variable to hold a class object between ASP.NET pages (in VB). In my constructor I check to see if the Session variable exists, and if it doesn't, I create one and populate it...
17
by: Control Freq | last post by:
Hi, Not sure if this is the right NG for this, but, is there a convention for the variable names of a Session variable? I am using .NET 2.0 in C#. I am new to all this .NET stuff, So, any...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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.