[SOLVED] Help needed with $_POST
Moderator: General Moderators
[SOLVED] Help needed with $_POST
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??
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??
Last edited by ericsodt on Wed Dec 03, 2003 1:25 pm, edited 1 time in total.
What is the name of the select box? Heres an example:
On the PHP page:
Use the $_POST of whatever the name of the selectbox is.
Code: Select all
<select name="Group1">
<option value="g1_e1_s1">g1_e1_s1</option>
<option value="g1_e1_s2">g1_e1_s2</option>
<option value="g1_e1_s3">g1_e1_s3</option>
</select>Code: Select all
<?php
echo "The selected option in Group 1 was $_POST['Group1']";
?>The actual HTML look like this:
however when I do this:
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:
Use the $_POST of whatever the name of the selectbox is.[/quote]
Code: Select all
<select name="g0_e0_s1" class="dropdown" >
<option selected = -1>
<option value=15>15</option>
<option value=14>14</option>
<option value=13>13</option>
<option value=12>12</option>
</select>Code: Select all
echo $_POSTї'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']";
?>Code: Select all
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>This is invalid:
$_POST can not be in the string, atleast thats what apache is saying to me when I try and copy that code...
Code: Select all
<?php
echo "The selected option in Group 1 was $_POST['Group1']";
?>DuFF wrote:What is the name of the select box? Heres an example:
On the PHP page:Code: Select all
<select name="Group1"> <option value="g1_e1_s1">g1_e1_s1</option> <option value="g1_e1_s2">g1_e1_s2</option> <option value="g1_e1_s3">g1_e1_s3</option> </select>Use the $_POST of whatever the name of the selectbox is.Code: Select all
<?php echo "The selected option in Group 1 was $_POST['Group1']"; ?>
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>
turn
into
Does that make any difference?
Code: Select all
<?php
echo "The selected option in Group 1 was $_POST['Group1']";
?>Code: Select all
<?php
echo "The selected option in Group 1 was ".$_POST['Group1']."";
?>does nothing.... thanks though, anymore suggestions?
Sami wrote:turn
intoCode: Select all
<?php echo "The selected option in Group 1 was $_POST['Group1']"; ?>
Does that make any difference?Code: Select all
<?php echo "The selected option in Group 1 was ".$_POST['Group1'].""; ?>
$_POST was added to PHP in 4.1.0.
http://www.php.net/manual/en/reserved.v ... ables.post
http://www.php.net/manual/en/reserved.v ... ables.post
I suggest an upgrade.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 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
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.
g0_e0_s1 and not the value of it
Code: Select all
echo "g0_d0_s1".$_POSTї'g0_e0_s1'];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.
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>';PHP Version: 4.0.5
Display Errors: On
Error Level: Not E_ALL
Register Globals: On
Display Errors: On
Error Level: Not E_ALL
Register Globals: On
JAM wrote:What the result's of the above code on the recieving page?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>';
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.postI suggest an upgrade.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.
just download and install the upgrade from http://www.php.net