Posting to DB Help

  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

Hello all. This is what I want to do, I have a page with 120 check boxes on it. It's a simple form to check things off when you have completed them. The problem that I'm having, I'm new to PHP; however, I've got a good working knowledge. What I'm having problem is, I want the checkbox's ID to post to the database in a field name value_name. This way, I don't have to create 120 fields in the database, I can create 3 fields, which are CK_ID, value_name, checked. CK_ID is a primary key and whenever you select checkbox with the ID of 50, then it will post to the database 50 in the value_name field and 1 int he checked field. Then if that check box ever gets unselected, then it would change the checked from a 1 to a 0. This way, I can run a query to show me all the check boxes that are selected with a 1.

Can somebody help me with the action script to make this happen? I would greatly appreciate it!!!

Thanks,
Jordon
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

You don't have to create tons of variables and things like that. You can have it in an array like so:

<input type="checkbox" name="check[]" />
<input type="checkbox" name="check[]" />
<input type="checkbox" name="check[]" />
<input type="checkbox" name="check[]" />
<input type="checkbox" name="check[]" />
<input type="checkbox" name="check[]" />
... on and on and on...

And then check each of the array values. The keys would be numeric, and the first checkbox would have a key of '0' the second checkbox would have a key of '1' and so on...

You would probably need a foreach statement which extracts the arrays key and value and validate it from there and store the key and the value to the database...

I could write you the script but I would probably ask for some monetary payment...
  • jordonshaw
  • Student
  • Student
  • User avatar
  • Posts: 96
  • Loc: Tennessee

Post 3+ Months Ago

Great, I think that I can build off of this. I've used arrays in the past and just didn't think about using them here. If I get stuck, we might take about the monetary payment!

Thanks,
Jordon
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Alright... until then :)

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 100 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.