I have a <select multiple="multiple">
to get multiple choices in php. After that I put it in a variable with the POST
method and the I try to at least echo the array out to ensure that my variable$authors
has the choices but it prints this error
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\ex\addBook.php on line 45
Here is my code:
<?php
include ("includes/connections.php");
$authors = $_POST["authors"];
foreach ($authors as $author)
{
echo $author;
}
?>
here is the 'select multiple' I have in html :
<?php multiple("author_ID", "author_firstname", "author_lastname", "author", "author_lastname", "authors"); ?> <span style="font-size: 12px; color: #666;">(Keep down Ctrl for selecting multiple authors)</span>
here is the multiple function:
<?php include ("includes/connections.php");
function multiple($intIdField, $strfNameField, $strlNameField, $strTableName, $strOrderField, $strNameOrdinal, $strMethod="asc") {
echo "<select multiple=\"multiple\" name=\"$strNameOrdinal\">\n";
$strQuery = "select $intIdField, $strfNameField, $strlNameField
from $strTableName
order by $strOrderField $strMethod";
$rsrcResult = mysql_query($strQuery);
while($arrayRow = mysql_fetch_assoc($rsrcResult)) {
$strA = $arrayRow["$intIdField"];
$strB = $arrayRow["$strlNameField"] . " " . $arrayRow["$strfNameField"];
echo "<option value=\"$strA \">$strB</option>\n";
}
echo "</select>";
}
?>
So I would guess that the $authors
variable would be an array and I would happily at least print, but as I already said this does not happen.
The Authors that are taken from the database are showing up correctly without any problem. the thing is I want the ones that are chosen from the 'select multiple' list to be echoed out.