Line 42 is the error. I'm not sure as to why it keeps saying it's not an array is one section but fails to find the array on line 42. I have tried to change the line to ($_POST['CINS'] as $cNum => $v) and ($CINS as $cNum => $v). Any insight or help would be appreciated.
<?php
$title = "fTest.php";
$action=$_SERVER['PHP_SELF'];
include("html-head.inc");
echo <<<HEREDOC
<header>
<h1>$title</h1>
</header>
HEREDOC;
if (!isset($_POST['submit']))
{
echo "<form method=\"post\" action=\"$action\">";
$CINS = array('101' => "CINS101",
'108' => "CINS108",
'121' => "CINS121",
'251' => "CINS251",
'254' => "CINS254");
echo "<p>Please pick your CINS classes:</p>";
echo "<ul>
";
foreach ($CINS as $key => $value)
{
echo "<li>";
echo "<input type=\"checkbox\" name=\"CINSc\" value=\"$value\"/>CINS$key" ;
echo "</li>
";
}
echo "</ul>
";
echo "<input type=\"reset\" name=\"reset\" value\"Reset\" />";
echo "<input type=\"submit\" name=\"submit\" value\"Submit\" />";
echo "</p>";
echo is_array($CINS) ? 'Array' : 'Not an array';
echo "
";
echo "</form>";
} // ends IF PORTION for ISSET
else
{
if (count($_POST['CINS'] > 0 ))
{
echo "<h2> Your picks are: </h2>
";
echo "<ul>
";
echo is_array($CINS) ? 'Array' : 'Not an array';
foreach ($_POST['CINS'] as $cNum => $v) //This is the error.
{
echo "\t<li>$v</li>
";
} // end of FOREACH cins
echo "</ul>
";
} // end of IF count CINS
} // end of ELSE portion for ISSET
?>
Your checkbox name should like below to consider it as an array
<input type="checkbox" name="CINS[]" value = "1" />
The <input>
name is an array, and I've found a spare </p>
that shouldn't be there.
Your coding style is going to cause A LOT of HEADACHES. I've cleaned it up a bit, I think this style will be much easier to handle.
<?php
$title = "fTest.php";
$action=$_SERVER['PHP_SELF'];
include("html-head.inc");
?>
<header>
<h1><?=$title?></h1>
</header>
<?php if (!isset($_POST['submit'])): ?>
<?php $CINS = array('101' => "CINS101",
'108' => "CINS108",
'121' => "CINS121",
'251' => "CINS251",
'254' => "CINS254"); ?>
<form method="post" action="<?=$action?>">
<p>Please pick your CINS classes:</p>
<ul>
<?php foreach ($CINS as $key => $value): ?>
<li>
<input type="checkbox" name="CINS[]" value="<?=$value?>" />CINS<?=$key?>
</li>
<?php endforeach; ?>
</ul>
<input type="reset" name="reset" value"Reset" />
<input type="submit" name="submit" value"Submit" />
</p> <!-- THIS TAG IS EXTRA WHERE DID IT COME FROM -->
<?= is_array($CINS) ? 'Array' : 'Not an array' ?>
</form>
<?php else if (count($_POST['CINS'] > 0 )): ?>
<h2>Your picks are: </h2>
<ul>
<?= is_array($CINS) ? 'Array' : 'Not an array' ?>
<?php foreach ($_POST['CINS'] as $cNum => $v): ?>
<li><?=$v?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>