nitation Posted August 25, 2008 Share Posted August 25, 2008 Hello Guys, I am uploading a file in php and everything seem working fine. A new request on the project was to upload the file into a folder on the server and the image name saved in MYSQL table. This as well is working alright. My question is, how do i insert multiple checkbox into my database. Kindly see an instance; checkbox student checkbox family checkbox workplace When a user click on the three checkboxes, how do i insert it to my database, capturing the value of each checkbox and inserting them in a new row. Thanks Quote Link to comment Share on other sites More sharing options...
joquius Posted August 25, 2008 Share Posted August 25, 2008 $_POST['student'] should equal "on" if it's selected. You could do the following: $fields = array ("student", "family", "work"); $add_to_db = array (); foreach ($fields as $field) { if (isset ($_POST[$field]) && $_POST[$field] == "on") { $add_to_db[] = $field; } } $fields_to_add_to_db = implode (",", $add_to_db); or something like that...not very elegant Quote Link to comment Share on other sites More sharing options...
nitation Posted August 25, 2008 Author Share Posted August 25, 2008 In my situation, the value for each check box is retrieved from my database. How do i use it in my array. See this. if each checkbox value =$categoryID that means my html would be like this. <input name=$categoryID type=checkbox value=$categoryID> What do i do. The family, student and work are coming from my database. That means there are unlimited checkboxes that would be available. Hope this is clear Thanks in advance Quote Link to comment 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.