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>
Form Array Question?
Moderator: General Moderators
hi mikeT
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
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
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
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
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.
Have you tried putting
Code: Select all
echo '<pre>';
print_r($HTTP_POST_VARS);
echo '</pre>';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.
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.twigletmac wrote:PS. There was no reason to be rude to mr_griff
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
(
їitem] => Array
(
ї0] => 56789
ї1] => 56789
)
їaction] => Go2
)mikeT
FYI
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
You can check it out here:
http://www.vbulletin.com/forum/showthre ... post347929
thx