Page 1 of 1

Form Array Question?

Posted: Tue Oct 08, 2002 11:57 pm
by mikeT
Hi

I am experienceing a strange problem which I cannot figure out. The following code works as I would expect with the CGI version on IIS, however on APACHE it returns "0 = 56789", instead of "0 = 123456789".

If you shorten the length of the field to 4 characters e.g. "1234", it returns nothing for the value. If you shorten the length of the field to 3 characters e.g. "123", it returns the value as it should, e.g. "123".

Can anyone tell me whats going on here, and/or tell me how to get around it?
-----------------------------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Form Array</title>
</head>
<body topmargin="50" leftmargin="200" marginheight="50" marginwidth="200">

<?
if (count($HTTP_POST_VARS) == 0)
{
?>
<form method="post" action="testForm.php">

<b>Number of items: </b>
<input type="text" name="itemCount" maxlength="1"><br>

<input type="submit" name="action" value="Go1">
</form>
<?
}
else if ($HTTP_POST_VARS["action"] == 'Go1')
{
?>
<form method="post" action="testForm.php">

<?
for ($i=0; $i < $HTTP_POST_VARS["itemCount"]; $i++)
{
echo '<b>Item '. ($i + 1) .': </b><input type="text" name="item['. $i .']" value="123456789"><br>';
}
?>

<input type="submit" name="action" value="Go2">
</form>
<?
}
else if ($HTTP_POST_VARS["action"] == 'Go2')
{
foreach ($HTTP_POST_VARS["item"] as $var => $val)
{
echo $var .' = '. $val .'<br>';
}
}
?>

</body>
</html>

Posted: Wed Oct 09, 2002 1:00 am
by mr_griff
Your code works fine for me. I don't see any problems.

hi mikeT

Posted: Wed Oct 09, 2002 1:11 am
by navid
hi miket
your problem is used the "if ($HTTP_POST_VARS['action'] == 'Go1')".
because value $HTTP_POST_VARS['action'] any will 'Go1'.

the tru source is:
/////////////////////

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Test Form Array</title>
</head>
<body topmargin="50" leftmargin="200" marginheight="50" marginwidth="200">

<?
if (count($HTTP_POST_VARS)==0)
{
?>
<form method="post" action="1.php">
<b>Number of items: </b>
<input type="text" name="itemCount" maxlength="1"><br>
<input type="hidden" name="submit" value="1">
<input type="submit" name="action" value="Go1">
</form>
<?
}
else
{
if ($HTTP_POST_VARS['action'] == 'Go1')
echo "<h1>$itemCount</h1>";

?>

</body>
</html>

/////////////////////

bay

Posted: Wed Oct 09, 2002 1:17 am
by mikeT
mr_griff wrote:Your code works fine for me. I don't see any problems.
So you actually tried the code? Because it is definately not working correctly for me, I've checked and double checked it :roll:

hmm.. anyone else got any suggestions?

Posted: Wed Oct 09, 2002 2:01 am
by twigletmac
Which version of Apache? There does not appear to be anything syntactically wrong with your code and it works as expected for me on IIS (as it did for you).

Have you tried putting

Code: Select all

echo '&lt;pre&gt;';
print_r($HTTP_POST_VARS);
echo '&lt;/pre&gt;';
at each stage of the process to see if you can spot where things are going wrong for you?

Mac

PS. There was no reason to be rude to mr_griff, he clearly stated that your code worked fine for him so I think you can safely assume that he did actually try the code.

Posted: Wed Oct 09, 2002 2:19 am
by mikeT
twigletmac wrote:PS. There was no reason to be rude to mr_griff
Sorry mr_griff, I didn't intend to be rude, what I meant to say is something like.. so you tried it and it worked fine too? That is strange because... blah blah blah.

Anyway, my host is using:

Apache/1.3.27
PHP Version 4.2.3

Yes twigletmac, I tried your suggestion, thanks, with the <pre> tags and they produced:

Code: Select all

Array
(
    &#1111;item] => Array
        (
            &#1111;0] => 56789
            &#1111;1] => 56789
        )

    &#1111;action] => Go2
)
Can't think of anything else relevant to put now, thanks everyone for your help, any more ideas?

mikeT

FYI

Posted: Thu Oct 10, 2002 6:03 pm
by mikeT
This problem turns out to be related to a compile problem in PHP 4.2.3

You can check it out here:
http://www.vbulletin.com/forum/showthre ... post347929

thx