Hi I'm using foreach to insert into my database multiple authors for a book.
Here is the foreach:
foreach ($_POST["authors"] as $author) 
{
    $sqlAuthor = "INSERT INTO book_author (book_ISBN, author_ID)
        VALUES('$isbn','$author')";
    mysql_query($sqlAuthor);
}
I am getting the authors with a select multiple from my page for which I have created a function to display in the select multiple the authors available.
The code is producing exactly what I want it to produce in the page from my database (the names of all the authors)
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>";
    }
?>
Now for some reason it throws the following errors:
Notice: Undefined index: authors in C:\xampp\htdocs\ex\addBook.php on line 63
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\ex\addBook.php on line 63
I think it tells me that it can't find the authors array but I find it very strange
Here the php code inside the html to call the multiple() function:
<?php multiple("author_ID", "author_firstname", "author_lastname", "author", "author_lastname", "authors"); ?>
Anyone has any idea what is wrong with my code?
 
     
     
    