★ wanayoo — archive 1999 http://www.devshed.com/Talk/Forums/Forum5/HTML/002361.htmlNouvelle recherche | Portail wanayoo
DevShed Menu
* DevShed Home
* Developer News
* DevShed Brain Dump




UBBFriend: Email This Page to Someone!
  DevShed Discussion Forums
  PHP
  checkboxes from a Mysql DB

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   checkboxes from a Mysql DB
tigg
Member
posted August 10, 2000 02:12 PM     Click Here to See the Profile for tigg     Edit/Delete Message Reply w/Quote
I'm creating a page that includes check boxes that are dynamically pulled from a MySQL database. I have gotten it to correctly pull up the boxes and name them, but when I make a change and submit, all of the values that were checked are set to 0 instead of 1.

This should print out a checkbox, checked if it is supposed to be, and take an argument to be passed when the user chooses to update the page.
When I submit my form, all of the checkboxes pass a value of zero even when they are checked.
Can you tell me if there is an error in this statement?


print "<td valign='top'>";
print "<input type=checkbox name=checkbox_$cat_name value='checked' $checked[$j]></td>";
print ${"checkbox_".$field_name}." !!!";
print "<td valign='top'>$list_cat_name</td>";


$checked[$j] - contains the value 'checked' or nothing set (correctly) earlier in the file
the checkboxes are named checkbox_(fieldname) [ex: checkbox_food]

The value 'checked' is passed to another file that updates the db

Shiju Rajan
Member
posted August 10, 2000 08:01 PM     Click Here to See the Profile for Shiju Rajan   Click Here to Email Shiju Rajan     Edit/Delete Message Reply w/Quote

print "<td valign='top'>";
print "<input type=checkbox name=checkbox_$cat_name value='checked' $checked[$j]></td>";
print ${"checkbox_".$field_name}." !!!";
print "<td valign='top'>$list_cat_name</td>";

tigg,

i think you should put value="1" in check box.

ie,


echo "<input type=\"checkbox\" name=\"checkbox_".$cat."_name\" value=\"1\" $checked[$j]></td>";


i hope that will solve your problem..


------------------
SR -
webshiju.com

"The fear of the LORD is the beginning of knowledge..."

tigg
Member
posted August 11, 2000 11:37 AM     Click Here to See the Profile for tigg     Edit/Delete Message Reply w/Quote
That didn't work.
I still get nothing but "!!!"s from the statement, so I believe that the problem has to be in the <input> statement
In 'values="foo"' foo is the value that is returned when the box is checked.

adossey
Junior Member
posted August 11, 2000 01:25 PM     Click Here to See the Profile for adossey   Click Here to Email adossey     Edit/Delete Message Reply w/Quote
I am doing a similar thing in one of my scripts. Here is what I am doing:

<input type="checkbox" value="show_email" name="show_email" <? if ($show_email == "show_email") echo "checked"; ?>>

This works like a charm! I'm just checking to see if @show_email has already been set, and if so, just output CHECKED, which turns on the checkbox. Hope this helps for you.

Alex Dossey

All times are MST (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply
Hop to:

Contact Us | DevShed.com

Copyright © 1997-2000 ngenuity. All rights reserved.

Powered by: Ultimate Bulletin Board, Version 5.41a
© Infopop Corporation (formerly Madrona Park, Inc.), 1998 - 1999.