472,973 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

unable to retain values in text box

Hi me again,
sorry to be a pain. Ive been struggling with this one all day. Hope you can
understand whats happening. First my script is below. Have a look and I'll
explain at the bottom what it does so far and is failing to do

*******************************
<?php
session_start();
header("Cache-control: private"); //IE 6 Fix
include("myconn.php");

$_SESSION['pupilfield'] = trim($_POST['pupilfield']);
$_SESSION['gender'] = trim($_POST['gender']);

?>
</head>
<body>

<br><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="370" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="196" height="28">Type Pupil Name</td>
<td colspan="2">Select Gender</td>
</tr>
<tr>
<td>
<input name="pupilfield" type="text" value="<?php echo
$_SESSION['pupilfield'];?>" >
</td>
<td width="78">Male
<input <?php if (!(strcmp($_SESSION['gender'],"1"))) {echo "CHECKED";}
?> name="gender" type="radio" value="1">
</td>
<td width="96">Female
<input <?php if (!(strcmp($_SESSION['gender'],"2"))) {echo "CHECKED";}
?> name="gender" type="radio" value="2"></td>
</tr>
</table><br>

<?php
$res = mysql_query ("SELECT * FROM commenttype WHERE username = '$username'
AND status = 0");
if (!$res) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
?>
Filter by Category><br>
<?php
while($row1 =& mysql_fetch_array($res)) {
extract($row1);
?>

<input name="catbutton" type="submit" value="<?php echo $TypeID; ?>">
<?php echo $typedesc;
}
?>
</form>

<?php
if (isset($_POST['catbutton'])) {
$commentresults = mysql_query ("SELECT * FROM comments WHERE username =
'$username' AND status = 0 AND TypeID=".$_POST['catbutton']);
}else{
$commentresults = mysql_query ("SELECT * FROM comments WHERE username =
'$username' AND status = 0");
}

if (!$commentresults) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
?>
<br>
Select Comment
<form action="<?php echo $_SERVER['PHP_SELF']; ?> " method="post"
enctype="multipart/form-data">
<select name="selectcomm" size="5" style="WIDTH: 100%">
<?php
while($row =& mysql_fetch_array($commentresults)) {
extract($row);
?>
<option value="<?php echo $comment; ?>"><?php echo $comment; ?><br>
</option>
<?php
}
?>
</select>
<input name="addcomm" type="submit" value="Add">
<?php
$_SESSION['savedcomm'] = trim($_SESSION['savedcomm'].'
'.$_POST['selectcomm']);?>

</form>

<form name="Form1">
<p class="BodyText">
<textarea name="savedcomm" rows="5" style="WIDTH: 100%"><?php echo
$_SESSION['savedcomm'];?></textarea>

<input type="button" onClick="CopyToClipboard(),Minimize();"
value="Clipboard" />
(When clicked the browser window minimizes)
</form>
</body>
</html>
***************************************
first form
OK well first an array of buttons is created with their values coming from a
database. a textbox is filled and radiobutton selected when this form is
posted on clicking a button in the array the page is resubmitted
('PHP_SELF') resulting in sessions being created from the text field and
radio buttons. The values of the textfield and radiouttons are set to the
sessions so that the values persist on the page during 'PHP_SELF'.

Problem arrises on the second form where values from a list are posted and
copied into the final textfield at the bottom. During this second form
posting the values in the textbox and radio buttons are lost. I want them to
remain until the sessions are made false. can anyone help.

I know its alot of code to untangle but Im really stuck on this one

Ian
May 29 '06 #1
6 4580
Ian Davies wrote:
Hi me again,
sorry to be a pain. Ive been struggling with this one all day. Hope you can
understand whats happening. First my script is below. Have a look and I'll
explain at the bottom what it does so far and is failing to do

<code sniped>
first form
OK well first an array of buttons is created with their values coming from a
database. a textbox is filled and radiobutton selected when this form is
posted on clicking a button in the array the page is resubmitted
('PHP_SELF') resulting in sessions being created from the text field and
radio buttons. The values of the textfield and radiouttons are set to the
sessions so that the values persist on the page during 'PHP_SELF'.

Problem arrises on the second form where values from a list are posted and
copied into the final textfield at the bottom. During this second form
posting the values in the textbox and radio buttons are lost. I want them to
remain until the sessions are made false. can anyone help.

I know its alot of code to untangle but Im really stuck on this one

Ian


Ian,

I haven't looked at your code in detail - but I think your problem is how the
data is being submitted.

When you submit a form, only data from that specific form is in the $_POST (or
$_GET) value. Data from other forms on the page will not be submitted.

If you want to keep data from the first form after submitting the second one,
you have a couple of choices. You can put the first form data in the session
(my favorite). You can also store it in hidden fields in the second form (also
works well).


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 29 '06 #2
hi jerry
the data is in a session, and it retains itself during the first form post.
however I cannot get it to remain when the second form posts, even though
the sessions are still true and the textbox and radiobuttons values are are
still set to the session. I think it has to do with the second form somehow.
it seems that it is influencing the textbox and radiobutton's values. but i
cant work out why
ian

"Jerry Stuckle" <js*******@attglobal.net> wrote in message
news:d4******************************@comcast.com. ..
Ian Davies wrote:
Hi me again,
sorry to be a pain. Ive been struggling with this one all day. Hope you can understand whats happening. First my script is below. Have a look and I'll explain at the bottom what it does so far and is failing to do

<code sniped>
first form
OK well first an array of buttons is created with their values coming from a database. a textbox is filled and radiobutton selected when this form is
posted on clicking a button in the array the page is resubmitted
('PHP_SELF') resulting in sessions being created from the text field and
radio buttons. The values of the textfield and radiouttons are set to the sessions so that the values persist on the page during 'PHP_SELF'.

Problem arrises on the second form where values from a list are posted and copied into the final textfield at the bottom. During this second form
posting the values in the textbox and radio buttons are lost. I want them to remain until the sessions are made false. can anyone help.

I know its alot of code to untangle but Im really stuck on this one

Ian


Ian,

I haven't looked at your code in detail - but I think your problem is how

the data is being submitted.

When you submit a form, only data from that specific form is in the $_POST (or $_GET) value. Data from other forms on the page will not be submitted.

If you want to keep data from the first form after submitting the second one, you have a couple of choices. You can put the first form data in the session (my favorite). You can also store it in hidden fields in the second form (also works well).


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


May 29 '06 #3
Rik
Ian Davies wrote:
hi jerry
the data is in a session, and it retains itself during the first form
post. however I cannot get it to remain when the second form posts,
even though the sessions are still true and the textbox and
radiobuttons values are are still set to the session. I think it has
to do with the second form somehow. it seems that it is influencing
the textbox and radiobutton's values. but i cant work out why
ian


I suspect the problem is this:
$_SESSION['pupilfield'] = trim($_POST['pupilfield']);
$_SESSION['gender'] = trim($_POST['gender']);

After the second form, this $_POST values are non-existent, so null, and
hence $_SESSION[key] get's set to null.

Use:
$_SESSION[key] = (isset($_POST[key])) ? trim($_POST[key]) : $_SESSION[key];

Grtz,
--
Rik Wasmus
May 30 '06 #4
Your a saviour Rik cheers
Works a treat.
out of interest what is the script doing? I cant work it out

Ian

"Rik" <lu************@hotmail.com> wrote in message
news:3b***************************@news2.tudelft.n l...
Ian Davies wrote:
hi jerry
the data is in a session, and it retains itself during the first form
post. however I cannot get it to remain when the second form posts,
even though the sessions are still true and the textbox and
radiobuttons values are are still set to the session. I think it has
to do with the second form somehow. it seems that it is influencing
the textbox and radiobutton's values. but i cant work out why
ian
I suspect the problem is this:
$_SESSION['pupilfield'] = trim($_POST['pupilfield']);
$_SESSION['gender'] = trim($_POST['gender']);

After the second form, this $_POST values are non-existent, so null, and
hence $_SESSION[key] get's set to null.

Use:
$_SESSION[key] = (isset($_POST[key])) ? trim($_POST[key]) :

$_SESSION[key];
Grtz,
--
Rik Wasmus

May 30 '06 #5
Rik
Ian Davies wrote:
$_SESSION[key] = (isset($_POST[key])) ? trim($_POST[key]) :
$_SESSION[key];

Your a saviour Rik cheers
Works a treat.
out of interest what is the script doing? I cant work it out


Search www.php.net for ternary operator:
http://nl2.php.net/manual/en/languag...comparison.php

Actually, it does the following:

if(isset($_POST[key]){ //checks wether a new $_POST value with the specific
key exists
$_SESSION[key] = trim($_POST[key]); //sets the session value to the
posted value
} else {
$_SESSION[key] = $_SESSION[key]; //keep the session variable the same as
it was
}

The ternary operator just saves a lot of lines in the code while doing
simple checks.

Grtz,
--
Rik Wasmus
May 30 '06 #6
thanks

will make a note of that one
ian
"Rik" <lu************@hotmail.com> wrote in message
news:cf***************************@news2.tudelft.n l...
Ian Davies wrote:
$_SESSION[key] = (isset($_POST[key])) ? trim($_POST[key]) :
$_SESSION[key]; Your a saviour Rik cheers
Works a treat.
out of interest what is the script doing? I cant work it out


Search www.php.net for ternary operator:
http://nl2.php.net/manual/en/languag...comparison.php

Actually, it does the following:

if(isset($_POST[key]){ //checks wether a new $_POST value with the

specific key exists
$_SESSION[key] = trim($_POST[key]); //sets the session value to the
posted value
} else {
$_SESSION[key] = $_SESSION[key]; //keep the session variable the same as it was
}

The ternary operator just saves a lot of lines in the code while doing
simple checks.

Grtz,
--
Rik Wasmus

May 30 '06 #7

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

Similar topics

1
by: J P Singh | last post by:
I have simple form where user enter the search criteria and the form is posted back to itself and runs a query based on the values that are entered. Everything is expect the values that the user...
2
by: Bill Cohagan | last post by:
In my app I'm validating an XML file against an XSD which contains several attribute default value specifications. I'm performing the validation via an xml document load() using a...
3
by: Penny Bond | last post by:
Hi, Any help or suggestions on this one would be gratefully appreciated: I have 2 aspx pages one is called 'Query' and the other 'Details'. Query page has a number of text boxes and drop...
6
by: the friendly display name | last post by:
Hello. If a convert a string (string number = "24.45") into a double, using the Convert class ((double doublenumber = Convert.ToDouble(number)), the result will have the value 2445. How do I...
1
by: TomJ | last post by:
Hey guys, I am attempting to use the following example: 'Session("Name")' to maintain a value between moduleA and moduleB. ModuleB captures the Session("Name") to be used by moduleA throughout its...
10
by: Sonasang | last post by:
Hi, I am creating a web page using ASP and Javascript. When submit button is clicked , It will search for the values in the input given(in the input box). How to retain the values in the...
0
by: nimjerry | last post by:
i am using db2 udb V 9 on aix 5.3 and in db2diag.log alwas has this error occurr below is sample message 2008-03-03-09.45.34.366406+420 I306667A443 LEVEL: Warning PID : 835622 ...
3
by: raaman rai | last post by:
Hi Fellas, i need to understand how to retain the submtted form values during an Edit/Update operation. When i add the information from a form, i retain the form values in the following way incase...
4
by: pankajsingh5k | last post by:
Hi guys, These question is for all the experts... Please help me before my brain explodes The problem is again with the formview control.. I have a formview and i have to use it that...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.