Re: Checkboxes
| From: | Ben Ramsey | Date: | Tue, 27 Apr 2004 13:45:00 +0000 |
| Subject: | Re: Checkboxes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-184755@lists.php.net to get a copy of this message | ||
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 " <input type='checkbox' name='".$name."' value='".$id."'> $name<br>";
to:
echo " <input type='checkbox' name='models[]' value='".$id."'> $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. .-- Regards, Ben Ramsey http://benramsey.com http://www.phpcommunity.org/wiki/People/BenRamsey<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 " <input type='checkbox' name='".$name."' value='".$id."'> $name<br>"; }} ?> <INPUT TYPE="hidden" name="add" value="set"><INPUT TYPE="submit" name="submit" value="Ajouter"></form>