By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,438 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

updating multiple checkbox entries into php mysql database

P: 63
Hi All..'mAtif..i've got stuck within checkboxes these days..i've got many input items like checkboxes,textarea and along with them there are many checkboxes...all the data except the checkbox's is comfortably getting entered into the database but the real problem is with the checkboxes..only one entry is being stored ...but i want to enter the multiple entries from the checkboxes to enter into the database...the form is a voting poll..and i have made use of arrays..but i'm not able to get the right way of how to enter the multiple checkbox entries into mysql..plz help..the code follows...It has two tables...the updata checkbox data is to be entered into the 'tally' table... .More than one votes can be dne through checkboxes and as they are checked,there entry should be made into the table..plz help.as quick as possible..thanx in advance...the code follows:

<Code removed>
Dec 7 '07 #1
Share this Question
Share on Google+
5 Replies


Markus
Expert 5K+
P: 6,050
Strange...

=\
this has happened on both of your threads..
Dec 7 '07 #2

P: 63
ya.it is atrange...plz help ..how culd i find its soluiton
Dec 8 '07 #3

rizwan6feb
100+
P: 108
This could help u.Check this
May 21 '08 #4

Atli
Expert 5K+
P: 5,058
Hi.

I have removed the 519 lines of code you posted.
Such a large amount of code can not be handled correctly, making you post appear empty.
Try posting an "example" of your code, perhaps the areas you feel will be most useful to us.

And besides that, 519 lines of code will scare most readers away ^^
May 21 '08 #5

Atli
Expert 5K+
P: 5,058
If you have multiple check-boxes, all named the same, followed by [], each representing an ID of a vote you want updated, you can accept them in PHP as an array.
You can use that array to build a list of ID's that need to be updated, and pass that into an IN() clause in your SQL.

For example:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['submitted'])) {
  3.   # Connect to the database
  4.   # ... You know the drill
  5.  
  6.   # Get the votes and *implode* them into a list
  7.   $votes = $_POST['vote'];
  8.   $voteList = implode(", ", $votes);
  9.  
  10.   # Create a query, using the list in a IN() clause
  11.   $SQL = "UPDATE tally SET tvote = tvote + 1 WHERE nid IN ({$voteList})";
  12.   echo "<pre>", $SQL, "</pre>";
  13. }
  14. ?>
  15.  
  16. <form action="?" method="post">
  17.   <input type="checkbox" name="vote[]" value="1" /> Vote 1 </br>
  18.   <input type="checkbox" name="vote[]" value="2" /> Vote 2 </br>
  19.   <input type="checkbox" name="vote[]" value="3" /> Vote 3 </br>
  20.   <input type="checkbox" name="vote[]" value="4" /> Vote 4 </br>
  21.   <input type="submit" name="submitted" />
  22. </form>
  23.  
May 21 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.