Form Array Question?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mikeT
Forum Newbie
Posts: 7
Joined: Sun Jul 14, 2002 4:32 pm

Form Array Question?

Post 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>
User avatar
mr_griff
Forum Commoner
Posts: 64
Joined: Tue Sep 17, 2002 11:11 am
Location: Bozeman, Montana

Post by mr_griff »

Your code works fine for me. I don't see any problems.
navid
Forum Commoner
Posts: 68
Joined: Tue Sep 24, 2002 3:14 am
Location: iran

hi mikeT

Post 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
mikeT
Forum Newbie
Posts: 7
Joined: Sun Jul 14, 2002 4:32 pm

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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.
mikeT
Forum Newbie
Posts: 7
Joined: Sun Jul 14, 2002 4:32 pm

Post 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
mikeT
Forum Newbie
Posts: 7
Joined: Sun Jul 14, 2002 4:32 pm

FYI

Post 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
Post Reply