471,863 Members | 1,211 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,863 software developers and data experts.

updating multiple checkbox entries into php mysql database

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
5 6760
6,050 Expert 4TB

this has happened on both of your threads..
Dec 7 '07 #2
ya.it is atrange...plz help ..how culd i find its soluiton
Dec 8 '07 #3
108 100+
This could help u.Check this
May 21 '08 #4
5,058 Expert 4TB

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
5,058 Expert 4TB
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
  6.   # Get the votes and *implode* them into a list
  7.   $votes = $_POST['vote'];
  8.   $voteList = implode(", ", $votes);
  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. ?>
  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>
May 21 '08 #6

Post your reply

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

Similar topics

2 posts views Thread by scott | last post: by
7 posts views Thread by Paige | last post: by
2 posts views Thread by dukeofwhelmsley | last post: by
6 posts views Thread by Rudi Ahlers | last post: by
33 posts views Thread by bill | last post: by
10 posts views Thread by chimambo | last post: by
6 posts views Thread by Al Moodie | last post: by
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.