bamfon Posted January 19, 2011 Share Posted January 19, 2011 well i got a few checbox (look below for code) i want to make it so that if i click the checkbox's it sends all the check box value to one column with "," in between them <input type="checkbox" name="genre" value="fighting" id="genre"/>fighting <input type="checkbox" name="genre" value="school life" id="genre" />school life <input name="genre" type="checkbox" id="genre" value="king" id="genre" />king <input name="genre" type="checkbox" id="genre" value="him" />him Quote Link to comment https://forums.phpfreaks.com/topic/224913-checkbox-database-error/ Share on other sites More sharing options...
denno020 Posted January 19, 2011 Share Posted January 19, 2011 You need to provide your php, as this is what will put the information into the database. You will also need to set the values of the checkboxes into an array. Something that I found out this week myself. When you process the form, you can check through the checkboxes array to see if it's set or not, and then append the value to a checkboxes string, which is then put into the datase. Denno Quote Link to comment https://forums.phpfreaks.com/topic/224913-checkbox-database-error/#findComment-1161765 Share on other sites More sharing options...
cyberRobot Posted January 19, 2011 Share Posted January 19, 2011 So basically, you want the values from all the boxes that are checked? If so, the first problem is that you'll need to change the checkbox code. Your current code has four checkboxes with the same name. So when the data is sent back to the server you'll only have one value if more than one is checked. <input type="checkbox" name="genre" id="genre" value="fighting" />fighting <input type="checkbox" name="genre" id="genre" value="school life" />school life <input type="checkbox" name="genre" id="genre" value="king" />king <input type="checkbox" name="genre" id="genre" value="him" />him Instead you'll want the checkboxes to have different names and ids. <input type="checkbox" name="genre1" id="genre1" value="fighting" />fighting <input type="checkbox" name="genre2" id="genre2" value="school life" />school life <input type="checkbox" name="genre3" id="genre3" value="king" />king <input type="checkbox" name="genre4" id="genre4" value="him" />him Now you'll have four different variables to work with in your script: echo $_GET['genre1'] . ', '; echo $_GET['genre2'] . ', '; echo $_GET['genre3'] . ', '; echo $_GET['genre4'] . ', '; Note that if your form is set to method="post" you'll need to change the above variables to $_POST['genre1'], etc. Quote Link to comment https://forums.phpfreaks.com/topic/224913-checkbox-database-error/#findComment-1161881 Share on other sites More sharing options...
PFMaBiSmAd Posted January 19, 2011 Share Posted January 19, 2011 You'll want to give your form field an array name - http://us3.php.net/manual/en/faq.html.php#faq.html.arrays so that you can use php's array functions to process the data. Quote Link to comment https://forums.phpfreaks.com/topic/224913-checkbox-database-error/#findComment-1161883 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.