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 Link to comment https://forums.phpfreaks.com/topic/121240-one-question-to-my-solution-image-upload/ 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 Link to comment https://forums.phpfreaks.com/topic/121240-one-question-to-my-solution-image-upload/#findComment-625013 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 Link to comment https://forums.phpfreaks.com/topic/121240-one-question-to-my-solution-image-upload/#findComment-625021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.