Re: determine number of entries Options (2)



On Jan 31, 10:08 am, question....@xxxxxxxxxxx wrote:
I've tried implementing your comments but can't make it work. Below
is all of my code (testing) could you point out my mistake because it
is still spitting out a "Warning: Invalid argument supplied for
foreach()" error message.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>

<?php
foreach($_SERVER['POST']['IngQty'] as $key => $value) {
echo $key." : ".$value."<br/>";
}

echo "Count: ".count($_SERVER['POST']['IngQty'])."<br/><hr>" ;
?>

<form id="form1" name="form1" method="post" action="">
<p>
<input type="text" name="IngQty[0]"><br>
<input type="text" name="IngQty[1]"><br>
<input type="text" name="IngQty[2]">
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>

</body>
</html>

Thank you for all your help! Is there a good tutorial you could
recommend or subject name that I should lookup that covers this (I
don't even know what I am trying to do is called).

QB

The first time the script is run the form hasn't been submitted so
$_SERVER['POST']['IngQty'] doesn't even exist. You need to check it
first:

?php
if(isset($_SERVER['POST']['IngQty']) && is_array($_SERVER['POST']
['IngQty'])) {
foreach($_SERVER['POST']['IngQty'] as $key => $value) {
echo $key." : ".$value."<br/>";
}

echo "Count: ".count($_SERVER['POST']['IngQty'])."<br/><hr>" ;
}
?>
.



Relevant Pages

  • Re: $request problem
    ... $array['key'] is an array with the string 'key' as index. ... The PHP manual says on this topic: ... strangely enough this warning showed up in the log only the ... first time I accessed the page! ...
    (comp.lang.php)
  • Re: $request problem
    ... $array['key'] is an array with the string 'key' as index. ... The PHP manual says on this topic: ... strangely enough this warning showed up in the log only the ... first time I accessed the page! ...
    (comp.lang.php)
  • Re: PHP sessions and disabled cookies
    ... Cookies are blocked in my ... I do not see the URL containing the session ID. ... [PHP] ... A warning appears if the specified function is not defined, ...
    (php.general)
  • getting PHP5 sessions working when browser doesnt accept cookies.
    ... Here is my PHP ... The brower URL does not contain the session ID ... A warning appears if the specified function is not defined, ... support by the security team. ...
    (php.general)
  • session trouble
    ... everything else considering PHP is working perfectly and as far as I see ... the session tmp file is created in my tmp dir and I really don't see a valid ... A warning appears if the specified function is not defined, ... Setting certain environment variables may be a potential security breach. ...
    (alt.php)