RE: [PHP] Re: Checkboxes

From: Date: Tue, 27 Apr 2004 14:07:10 +0000
Subject: RE: [PHP] Re: Checkboxes
Groups: php.general 
Request: Send a blank email to php-general+get-184758@lists.php.net to get a copy of this message
Something I've done in Perl is when creating the page with multiple checkboxes, I create the checkbox like this: <input type=CHECKBOX name=check~$name > And then when the page is posted, split each of the posted variables by the '~' and by this you can tell which items were checked. Just one way to do it. Stanley G. Martin System Administrator Sprint - EAS Business Intelligence Stanley.G.Martin@mail.sprint.com -----Original Message----- From: Ben Ramsey [mailto:lists@benramsey.com] Sent: Tuesday, April 27, 2004 8:45 AM To: php-general@lists.php.net Subject: [PHP] Re: Checkboxes Be more specific with what you mean by "the form doesn't work." How doesn't it work? Is it not passing the correct values, etc.? Please describe in more detail. Depending on what you're trying to do, I would change this line: echo "&nbsp;&nbsp;<input type='checkbox' name='".$name."' value='".$id."'>&nbsp;&nbsp;$name<br>"; to: echo "&nbsp;&nbsp;<input type='checkbox' name='models[]' value='".$id."'>&nbsp;&nbsp;$name<br>"; This will add all the id's for all items to an array named "models" that can be accessed through $_POST['models'] in the action script. Then, in add_prodrel.php (the action script), do print_r($_POST); to see what form elements and values are truly being passed. Also, you may try print_r($_POST['models']); to see what's being passed in the models array. Hope this helps you debug your problem. Phpu wrote: > I have this script: > > Each brand has more that one model. When i chose a brand it displays chackboxes for each model in a form.. > Now i want to select some models and introduce them into database. > > How can i do that. This script display the each model, but wen i chose some of them the form doesn't work. . > > > <FORM METHOD=POST ACTION="add_prodrel.php" enctype="multipart/form-data" NAME="doublecombo"> > <? > $query12 = "SELECT id, brand_id, model_id FROM shop_items WHERE id='$showdetail'"; > > $result12 = mysql_query($query12) or die("error in query - $query12 - ".mysql_error()); > > while($row = mysql_fetch_row($result12)) { > > list($id, $brand_id, $model_id) = $row; > > $query3 = "SELECT id, brand_id, name FROM shop_models WHERE brand_id='$brand_id'"; > > $result3 = mysql_query($query3) or die("error in query - $query3 - ".mysql_error()); > > while($row = mysql_fetch_row($result3)) { > > list($id, $brand_id, $name) = $row; > > echo "&nbsp;&nbsp;<input type='checkbox' name='".$name."' value='".$id."'>&nbsp;&nbsp;$name<br>"; > > > > } > > } > > ?> > <INPUT TYPE="hidden" name="add" value="set"><INPUT > TYPE="submit" name="submit" value="Ajouter"> > </form> > -- Regards, Ben Ramsey http://benramsey.com http://www.phpcommunity.org/wiki/People/BenRamsey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#184758) next »