arrays in forms.

From: Date: Sat, 07 Jul 2001 22:08:42 +0000
Subject: arrays in forms.
Groups: php.general 
Request: Send a blank email to php-general+get-56675@lists.php.net to get a copy of this message
Hi, I have a multi-select listbox set up like this: Author (you are able to select more than one.<a href="addauthor.php">Click here to add a new author</a>)<br>: <select name="author" multiple size=5> <?php $result = mysql_query("SELECT AUTHOR_ID, AUTHOR_FNAME, AUTHOR_LNAME FROM AUTHORS;") or die(mysql_error()); while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
         $option = "<option value=" . $row["AUTHOR_ID"] . ">" . $row["AUTHOR_FNAME"] . " " . $row["AUTHOR_LNAME"] . "</option>";
         echo $option;
} ?> </select><br> I then have a bit of code that parses through and checks which authors they selected, if any. if isset($author) {
        if is_array($author) {
                foreach($authors as $key=>$value) {
                        $query = "INSERT INTO BYLINE(TITLE_ID, AUTHOR_ID) VALUES(" . $titleid . "," . $value . ");";
                        mysql_auery($query) or die(echo mysql_error());
                 }
        } else {
                $query = "INSERT INTO BYLINE(TITLE_ID, AUTHOR_ID) VALUES(" . $titleid . "," . $author . ");";
                mysql_auery($query) or die(echo mysql_error());
        }
} What I'd like to know is, is this correct, incorrect, redundant, etc? John Meyer john_meyer@geocities.com Programmer If we didn't have Microsoft, we'd have to blame ourselves for all of our programs crashing

« previous php.general (#56675) next »