Page 1 of 1

[SOLVED] Help needed with $_POST

Posted: Tue Dec 02, 2003 1:44 pm
by ericsodt
I have a form and this form can contain any number of groups (1-10) and each group contains 3 drop down boxes. (ie group 5 with 3 drop downs, and group 10 with 3 drop downs, any combination really)

I have named each select box after the group and subgroup it is in. For example. G0_SG0_SB0, G0_SG1_SB0, etc [first example: Group 0, SubGroup 0, SelectBox 0].

After the user enters the select box information, I post the data through the form onto page2. My problem is I am trying to get a $_POST[] on the select box information and coming up with nothing.

exmple:
for($g=0; $g<=$groupCount; $g++){
for($e=0; $e<=$subGroupCount; $e++){
for($s=1; $s<=3; $s++){
$setArray[] = "g".$g."_e".$e."_s".$s; // produces g0_e0_s0,
// g0_e0_s1, etc...
}
}
}

The code above creates the names of the select boxes. Now that the names are all created, I need to get their selected information, so I use the $_POST... However it does not work, I can not retrieve what the user selected.

Any thoughts??

Posted: Tue Dec 02, 2003 3:42 pm
by DuFF
What is the name of the select box? Heres an example:

Code: Select all

&lt;select name="Group1"&gt;
&lt;option value="g1_e1_s1"&gt;g1_e1_s1&lt;/option&gt;
&lt;option value="g1_e1_s2"&gt;g1_e1_s2&lt;/option&gt;
&lt;option value="g1_e1_s3"&gt;g1_e1_s3&lt;/option&gt;
&lt;/select&gt;
On the PHP page:

Code: Select all

<?php
echo "The selected option in Group 1 was $_POST['Group1']";
?>
Use the $_POST of whatever the name of the selectbox is.

Posted: Wed Dec 03, 2003 12:01 pm
by ericsodt
The actual HTML look like this:

Code: Select all

&lt;select name="g0_e0_s1" class="dropdown"  &gt;
 &lt;option selected = -1&gt;
 &lt;option value=15&gt;15&lt;/option&gt;
 &lt;option value=14&gt;14&lt;/option&gt;
 &lt;option value=13&gt;13&lt;/option&gt;
 &lt;option value=12&gt;12&lt;/option&gt;
 &lt;/select&gt;
however when I do this:

Code: Select all

echo $_POST&#1111;'g0_e0_s1'];

nothing is returned on the page. For some reason $_POST does not work, am I using an outdated version of PHP... doesnt make sense, but I am searching for this answer and it is NOT coming.


_____________________________________________________________

On the PHP page:

Code: Select all

<?php
echo "The selected option in Group 1 was $_POST['Group1']";
?>
Use the $_POST of whatever the name of the selectbox is.[/quote]

Posted: Wed Dec 03, 2003 12:04 pm
by Chambrln
Well first off you'd want to make sure you are submitting your form via post and not get

Code: Select all

<form name=whatever method=post action=pagename.php>

Posted: Wed Dec 03, 2003 12:06 pm
by ericsodt
This is invalid:

Code: Select all

<?php
echo "The selected option in Group 1 was $_POST['Group1']";
?>
$_POST can not be in the string, atleast thats what apache is saying to me when I try and copy that code...

DuFF wrote:What is the name of the select box? Heres an example:

Code: Select all

&lt;select name="Group1"&gt;
&lt;option value="g1_e1_s1"&gt;g1_e1_s1&lt;/option&gt;
&lt;option value="g1_e1_s2"&gt;g1_e1_s2&lt;/option&gt;
&lt;option value="g1_e1_s3"&gt;g1_e1_s3&lt;/option&gt;
&lt;/select&gt;
On the PHP page:

Code: Select all

<?php
echo "The selected option in Group 1 was $_POST['Group1']";
?>
Use the $_POST of whatever the name of the selectbox is.

Posted: Wed Dec 03, 2003 12:09 pm
by ericsodt
I am def. doing that...

Code: Select all

<!-- ^^^^^^ HEADER ^^^^^ --> 
<form name="group0" id="group0" method="POST"  action="insert.php">
<input type="hidden" name="exArray" value="5,6,14,15">
ect...
ect...
ect...
Chambrln wrote:Well first off you'd want to make sure you are submitting your form via post and not get

Code: Select all

<form name=whatever method=post action=pagename.php>

Posted: Wed Dec 03, 2003 12:11 pm
by m3mn0n
turn

Code: Select all

<?php
echo "The selected option in Group 1 was $_POST['Group1']"; 
?>
into

Code: Select all

<?php
echo "The selected option in Group 1 was ".$_POST['Group1'].""; 
?>
Does that make any difference?

Posted: Wed Dec 03, 2003 12:14 pm
by ericsodt
does nothing.... thanks though, anymore suggestions?
Sami wrote:turn

Code: Select all

<?php
echo "The selected option in Group 1 was $_POST['Group1']"; 
?>
into

Code: Select all

<?php
echo "The selected option in Group 1 was ".$_POST['Group1'].""; 
?>
Does that make any difference?

Posted: Wed Dec 03, 2003 12:16 pm
by m3mn0n
$_POST was added to PHP in 4.1.0.

http://www.php.net/manual/en/reserved.v ... ables.post
HTTP POST variables: $_POST
Note: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_VARS.

An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_POST; to access it within functions or methods, as you do with $HTTP_POST_VARS.

$HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_POST and $HTTP_POST_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
I suggest an upgrade.

Posted: Wed Dec 03, 2003 12:20 pm
by ericsodt
I had to edit my original message, there is no error message returned now, however it is not presenting me with any information, just the string
g0_e0_s1 and not the value of it

Code: Select all

echo "g0_d0_s1".$_POST&#1111;'g0_e0_s1'];
this is the only code on the page, I just want to see if the page is getting what the user has selected on the previous page, and page 2 is not receiving what page 1 is sending it.

Sami wrote:It's possible the error occurs above the line it reports.

Is that the only line in the script? If not, post the lines above it.

Posted: Wed Dec 03, 2003 12:49 pm
by JAM

Code: Select all

echo '<pre>';
echo 'PHP Version: '.phpversion()."\n";
echo 'Display Errors: '.(ini_get('display_errors') == '1' ? 'On' : 'Off')."\n";
echo 'Error Level: '.(ini_get('error_reporting') == '2047' ? 'E_ALL' : 'Not E_ALL')."\n";
echo 'Register Globals: '.(ini_get('register_globals') == '' ? 'Off' : 'On')."\n";
print_r($_POST);
echo '</pre>';
What the result's of the above code on the recieving page?

Posted: Wed Dec 03, 2003 1:01 pm
by ericsodt
PHP Version: 4.0.5
Display Errors: On
Error Level: Not E_ALL
Register Globals: On



JAM wrote:

Code: Select all

echo '<pre>';
echo 'PHP Version: '.phpversion()."\n";
echo 'Display Errors: '.(ini_get('display_errors') == '1' ? 'On' : 'Off')."\n";
echo 'Error Level: '.(ini_get('error_reporting') == '2047' ? 'E_ALL' : 'Not E_ALL')."\n";
echo 'Register Globals: '.(ini_get('register_globals') == '' ? 'Off' : 'On')."\n";
print_r($_POST);
echo '</pre>';
What the result's of the above code on the recieving page?

Posted: Wed Dec 03, 2003 1:03 pm
by ericsodt
THanks so much guys... when I use the $HTTP_POST_VARS it comes back with the correct information, now the question is how do I upgrade from 4.0.5 ????
Sami wrote:$_POST was added to PHP in 4.1.0.

http://www.php.net/manual/en/reserved.v ... ables.post
HTTP POST variables: $_POST
Note: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_VARS.

An associative array of variables passed to the current script via the HTTP POST method. Automatically global in any scope.

This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_POST; to access it within functions or methods, as you do with $HTTP_POST_VARS.

$HTTP_POST_VARS contains the same initial information, but is not an autoglobal. (Note that HTTP_POST_VARS and $_POST are different variables and that PHP handles them as such)

If the register_globals directive is set, then these variables will also be made available in the global scope of the script; i.e., separate from the $_POST and $HTTP_POST_VARS arrays. For related information, see the security chapter titled Using Register Globals. These individual globals are not autoglobals.
I suggest an upgrade.

Posted: Wed Dec 03, 2003 2:02 pm
by infolock
just download and install the upgrade from http://www.php.net