473,396 Members | 1,907 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,396 software developers and data experts.

Retaining form values in PHP

Configuration:

PHP 4.3.9
Apache 2.0.52

Hello PHP group,

I am a novice to PHP. I have searched through the newsgroup on my
issue but I am not sure I know what I am missing.

I am creating an application to help the veterinarians at the animal
hospital I work at.

I have a form which present a select list of animals (from a database
query) which belong to a client. I can see the animal names in memory
and the client account number. When I select the appropriate animal
from the list, I see the selected animal name ("spot") but everything
else in memory I need (client account number) has disappeared. I've
heard this is normal.

I've tried storing the client account number is a session
($_SESSION['account_number"] before the submit, and I can see it, but
this value too seems to be eliminated once the form is submitted.

I've read I can use Javascript to get around this, but I want to learn
the PHP way.

Thanks for your time and help.

Steve Poe

Aug 3 '06 #1
9 4541
Steve Poe wrote:
I have a form which present a select list of animals (from a database
query) which belong to a client. I can see the animal names in memory and
the client account number. When I select the appropriate animal from the
list, I see the selected animal name ("spot") but everything else in
memory I need (client account number) has disappeared. I've heard this is
normal.

I've tried storing the client account number is a session
($_SESSION['account_number"] before the submit, and I can see it, but this
value too seems to be eliminated once the form is submitted.
The "normal" way to do this, AFAIK, is to use hidden form values:

<form ...>
<input type="hidden" name="account_number" value="12345" />
<!-- all of your normal form stuff goes here -->
</form>

Then your $_POST will include a value for account_number.

HTH,
--
Benjamin D. Esham
bd*****@gmail.com | AIM: bdesham128 | Jabber: same as e-mail
Vrei să pleci dar nu mă, nu mă iei,
nu mă, nu mă iei, nu mă, nu mă, nu mă iei.
Chipul tău şi dragostea din tei, / mi-amintesc de ochii tăi.

Aug 3 '06 #2
Steve Poe wrote:
Configuration:

PHP 4.3.9
Apache 2.0.52

Hello PHP group,

I am a novice to PHP. I have searched through the newsgroup on my
issue but I am not sure I know what I am missing.

I am creating an application to help the veterinarians at the animal
hospital I work at.

I have a form which present a select list of animals (from a database
query) which belong to a client. I can see the animal names in memory
and the client account number. When I select the appropriate animal
from the list, I see the selected animal name ("spot") but everything
else in memory I need (client account number) has disappeared. I've
heard this is normal.

I've tried storing the client account number is a session
($_SESSION['account_number"] before the submit, and I can see it, but
this value too seems to be eliminated once the form is submitted.

I've read I can use Javascript to get around this, but I want to learn
the PHP way.

Thanks for your time and help.

Steve Poe
Without seeing your code it's impossible to tell.

However, if you're submitting a form, remember that each page has it's
own variables. PHP doesn't remember data from one page to the next.
The only ways to pass data from one page to the next is either with the
$_SESSION or hidden fields in your form.

As to the $_SESSION data disappearing - it shouldn't. Are you calling
session_start() at the beginning of EVERY page (before ANY data is
output) where you use session data?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 3 '06 #3
Benjamin,

Thanks for your advice. I'll look into the hidden values.

Steve
Benjamin Esham wrote:
Steve Poe wrote:
I have a form which present a select list of animals (from a database
query) which belong to a client. I can see the animal names in memory and
the client account number. When I select the appropriate animal from the
list, I see the selected animal name ("spot") but everything else in
memory I need (client account number) has disappeared. I've heard this is
normal.

I've tried storing the client account number is a session
($_SESSION['account_number"] before the submit, and I can see it, but this
value too seems to be eliminated once the form is submitted.

The "normal" way to do this, AFAIK, is to use hidden form values:

<form ...>
<input type="hidden" name="account_number" value="12345" />
<!-- all of your normal form stuff goes here -->
</form>

Then your $_POST will include a value for account_number.

HTH,
--
Benjamin D. Esham
bd*****@gmail.com | AIM: bdesham128 | Jabber: same as e-mail
Vrei sa pleci dar nu ma, nu ma iei,
nu ma, nu ma iei, nu ma, nu ma, nu ma iei.
Chipul tau si dragostea din tei, / mi-amintesc de ochii tai.
Aug 3 '06 #4
Jerry,

Thanks for replying. I understand it's hard to see the problem in
context without seeing the code. I'll try the feedback offered by most
then post if I get stuck.
>PHP doesn't remember data from one page to the next.
The only ways to pass data from one page to the next is either with the
$_SESSION or hidden fields in your form.
I have the my inputs/forms in separate php pages. It seemed the input
of a client account number passed back to the main php fine
As to the $_SESSION data disappearing - it shouldn't. Are you calling
session_start() at the beginning of EVERY page (before ANY data is
output) where you use session data?
No, session_start() is not on EVERY page. I have tried it on the two
pages I have separately but not both of them together.

Steve
Jerry Stuckle wrote:
Steve Poe wrote:
Configuration:

PHP 4.3.9
Apache 2.0.52

Hello PHP group,

I am a novice to PHP. I have searched through the newsgroup on my
issue but I am not sure I know what I am missing.

I am creating an application to help the veterinarians at the animal
hospital I work at.

I have a form which present a select list of animals (from a database
query) which belong to a client. I can see the animal names in memory
and the client account number. When I select the appropriate animal
from the list, I see the selected animal name ("spot") but everything
else in memory I need (client account number) has disappeared. I've
heard this is normal.

I've tried storing the client account number is a session
($_SESSION['account_number"] before the submit, and I can see it, but
this value too seems to be eliminated once the form is submitted.

I've read I can use Javascript to get around this, but I want to learn
the PHP way.

Thanks for your time and help.

Steve Poe

Without seeing your code it's impossible to tell.

However, if you're submitting a form, remember that each page has it's
own variables. PHP doesn't remember data from one page to the next.
The only ways to pass data from one page to the next is either with the
$_SESSION or hidden fields in your form.

As to the $_SESSION data disappearing - it shouldn't. Are you calling
session_start() at the beginning of EVERY page (before ANY data is
output) where you use session data?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 3 '06 #5
Steve Poe wrote:
Jerry,

Thanks for replying. I understand it's hard to see the problem in
context without seeing the code. I'll try the feedback offered by most
then post if I get stuck.

>>PHP doesn't remember data from one page to the next.
The only ways to pass data from one page to the next is either with the
$_SESSION or hidden fields in your form.


I have the my inputs/forms in separate php pages. It seemed the input
of a client account number passed back to the main php fine
In order for it to be passed back to the main php, you must have it in
the $_SESSION or an input field of some type (hidden or not).
>
>>As to the $_SESSION data disappearing - it shouldn't. Are you calling
session_start() at the beginning of EVERY page (before ANY data is
output) where you use session data?


No, session_start() is not on EVERY page. I have tried it on the two
pages I have separately but not both of them together.

Steve
It needs to be on EVERY PAGE which uses sessions. Otherwise the
$_SESSION array will not be usable on that page. You can save data to
$_SESSION, but it won't be saved in the session.

>
Jerry Stuckle wrote:
>>Steve Poe wrote:
>>>Configuration:

PHP 4.3.9
Apache 2.0.52

Hello PHP group,

I am a novice to PHP. I have searched through the newsgroup on my
issue but I am not sure I know what I am missing.

I am creating an application to help the veterinarians at the animal
hospital I work at.

I have a form which present a select list of animals (from a database
query) which belong to a client. I can see the animal names in memory
and the client account number. When I select the appropriate animal
from the list, I see the selected animal name ("spot") but everything
else in memory I need (client account number) has disappeared. I've
heard this is normal.

I've tried storing the client account number is a session
($_SESSION['account_number"] before the submit, and I can see it, but
this value too seems to be eliminated once the form is submitted.

I've read I can use Javascript to get around this, but I want to learn
the PHP way.

Thanks for your time and help.

Steve Poe

Without seeing your code it's impossible to tell.

However, if you're submitting a form, remember that each page has it's
own variables. PHP doesn't remember data from one page to the next.
The only ways to pass data from one page to the next is either with the
$_SESSION or hidden fields in your form.

As to the $_SESSION data disappearing - it shouldn't. Are you calling
session_start() at the beginning of EVERY page (before ANY data is
output) where you use session data?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 4 '06 #6
I must more clueless than I thought. I added 'session_start();' to the
begining of each PHP I am using and I still do not see the client
account after I submit it. I see it in the _SESSION *before* I hit
submit.

Steve
It needs to be on EVERY PAGE which uses sessions. Otherwise the
$_SESSION array will not be usable on that page. You can save data to
$_SESSION, but it won't be saved in the session.
Aug 4 '06 #7
Jerry (and felllow PHP gang),

Well, I still could not get sessions to work past a submitted form, but
I had a breakthrough. Using the hidden input fields like:
'<input type="hidden" name="client_account" value="<? echo
str_pad($_POST["account_number"], 6, " ", STR_PAD_LEFT)?>">' I was
able to see the variable with the value in it.

Until I figure out why sessions do not work, I can at least add hidden
input fields to transfer needed values.

Thanks.

Steve
Steve Poe wrote:
I must more clueless than I thought. I added 'session_start();' to the
begining of each PHP I am using and I still do not see the client
account after I submit it. I see it in the _SESSION *before* I hit
submit.

Steve
It needs to be on EVERY PAGE which uses sessions. Otherwise the
$_SESSION array will not be usable on that page. You can save data to
$_SESSION, but it won't be saved in the session.
Aug 4 '06 #8
Steve Poe wrote:
Jerry (and felllow PHP gang),

Well, I still could not get sessions to work past a submitted form, but
I had a breakthrough. Using the hidden input fields like:
'<input type="hidden" name="client_account" value="<? echo
str_pad($_POST["account_number"], 6, " ", STR_PAD_LEFT)?>">' I was
able to see the variable with the value in it.

Until I figure out why sessions do not work, I can at least add hidden
input fields to transfer needed values.

Thanks.

Steve
Steve Poe wrote:
>>I must more clueless than I thought. I added 'session_start();' to the
begining of each PHP I am using and I still do not see the client
account after I submit it. I see it in the _SESSION *before* I hit
submit.

Steve

>>>It needs to be on EVERY PAGE which uses sessions. Otherwise the
$_SESSION array will not be usable on that page. You can save data to
$_SESSION, but it won't be saved in the session.

Steve,

Ensure all of your errors are enabled (E_ALL) and you're displaying the
errors.

Chances are you're sending something to the client (even a single white
space character) before calling session-start().

session_start() MUST be called before ANY output is sent to the client.
Enabling all errors will display a warning to that effect if you are
doing it.

And your sessions won't work.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 5 '06 #9
Try the PHP Manual, there is a quite clear example:

http://au2.php.net/manual/en/function.session-start.php

Hope this helps.

William
Jerry Stuckle wrote:
Steve Poe wrote:
Jerry (and felllow PHP gang),

Well, I still could not get sessions to work past a submitted form, but
I had a breakthrough. Using the hidden input fields like:
'<input type="hidden" name="client_account" value="<? echo
str_pad($_POST["account_number"], 6, " ", STR_PAD_LEFT)?>">' I was
able to see the variable with the value in it.

Until I figure out why sessions do not work, I can at least add hidden
input fields to transfer needed values.

Thanks.

Steve
Steve Poe wrote:
>I must more clueless than I thought. I added 'session_start();' to the
begining of each PHP I am using and I still do not see the client
account after I submit it. I see it in the _SESSION *before* I hit
submit.

Steve
It needs to be on EVERY PAGE which uses sessions. Otherwise the
$_SESSION array will not be usable on that page. You can save data to
$_SESSION, but it won't be saved in the session.

Steve,

Ensure all of your errors are enabled (E_ALL) and you're displaying the
errors.

Chances are you're sending something to the client (even a single white
space character) before calling session-start().

session_start() MUST be called before ANY output is sent to the client.
Enabling all errors will display a warning to that effect if you are
doing it.

And your sessions won't work.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 6 '06 #10

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

Similar topics

5
by: Suresh Kumaran | last post by:
How do you retain the last value the user keyed in a text box? I should be able to show the values when the user runs the executable for the second time. Appreciate help. Suresh
1
by: cgplays.com | last post by:
I have a select-pulldown at http://computergroupplays.com/fb-pres2.asp that changes the 3rd pulldown (Dbase) depending on what the user enters in the 2nd (Wk). My associate wants the values inside...
19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
0
by: Earl Teigrob | last post by:
I have a page that reads values from an XML file to display to the user. The page also has a control panel that allows administrators to update the XML file with new values. When an administrator...
2
by: cFleury | last post by:
This system works in a intranet w/ some 200 stations and this particular form is retaining its values among different stations...like if I enter some values in the form on station 1 walk to station...
3
by: desh | last post by:
hello How to retain the values in form tag ,in case user enter wrong information.
3
by: Nick Douglas | last post by:
I have an unbound form to generate reports from in an mdb that we share on our network drive. The users selects several options for the report, such as what to view, the sort order, etc. These...
2
by: s4lin | last post by:
problem is pagination not retaining data field i have form with general data field, and i need to select some option which is store in database, so i open another page with retrieving data from...
2
by: anusha.vempati9 | last post by:
Hi All, I am calling a cgi file from a perl module. The cgi file contains the HTML form and some HTML fields(like check boxes). In my logic, I am trying to submit the form and calling the same...
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
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: 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:
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
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.