dulskel11 Posted August 1, 2016 Share Posted August 1, 2016 This code isn't working, and nothing comes up in the error logs, but also nothing inserts into the database. Can someone please take a look and see if there is something I'm missing? Please excuse my poor beginner PHP and HTML Quote Link to comment https://forums.phpfreaks.com/topic/301717-inserting-multiple-checkbox-values-into-a-single-mysql-database-column/ Share on other sites More sharing options...
benanamen Posted August 1, 2016 Share Posted August 1, 2016 (edited) Pictures are for hanging on the wall. Post your actual code. With that said, you are using obsolete code that has been completely removed from Php. You need to use PDO. https://phpdelusions.net/pdo Edited August 1, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/301717-inserting-multiple-checkbox-values-into-a-single-mysql-database-column/#findComment-1535422 Share on other sites More sharing options...
Jacques1 Posted August 1, 2016 Share Posted August 1, 2016 Your error handling is broken (you check the query string $query which is always truthy), and your VALUES have no category. But, yes, do use PDO. It will save you many, many hours or writing useless code and struggling with strange problems. Quote Link to comment https://forums.phpfreaks.com/topic/301717-inserting-multiple-checkbox-values-into-a-single-mysql-database-column/#findComment-1535425 Share on other sites More sharing options...
cyberRobot Posted August 2, 2016 Share Posted August 2, 2016 To fix the error handling, see Example #1 here: http://php.net/manual/en/function.mysql-query.php Of course, you will want to move away from the mysql_* functions as soon as possible, as benanamen and Jacques1 have suggested. Quote Link to comment https://forums.phpfreaks.com/topic/301717-inserting-multiple-checkbox-values-into-a-single-mysql-database-column/#findComment-1535441 Share on other sites More sharing options...
Yohanne Posted August 17, 2016 Share Posted August 17, 2016 use for loop..... for($i=0; $i <count($category); $i++) { $array = array('data =>', $data, 'year =>', $year, 'month =>', $month, 'day =>', $day, 'entrydate =>', $entrydate, 'envlopeNum =>', $envlopeNum, 'note =>', $note, 'category =>', $category[$i]); $query = "insert . . . . . . values $array . . . ."; // function insert } Quote Link to comment https://forums.phpfreaks.com/topic/301717-inserting-multiple-checkbox-values-into-a-single-mysql-database-column/#findComment-1536252 Share on other sites More sharing options...
Jacques1 Posted August 17, 2016 Share Posted August 17, 2016 What? Quote Link to comment https://forums.phpfreaks.com/topic/301717-inserting-multiple-checkbox-values-into-a-single-mysql-database-column/#findComment-1536253 Share on other sites More sharing options...
Yohanne Posted August 17, 2016 Share Posted August 17, 2016 i just gave an idea and what is wrong. . .? Quote Link to comment https://forums.phpfreaks.com/topic/301717-inserting-multiple-checkbox-values-into-a-single-mysql-database-column/#findComment-1536254 Share on other sites More sharing options...
Jacques1 Posted August 17, 2016 Share Posted August 17, 2016 Your reply is two weeks late, it doesn't have anything to do with the problem, and it makes no sense. When you need to insert one item with four categories, you don't insert four items. Either you insert one item and three category associations (this is the correct way, but it requires an extra table), or you insert one item with a comma-separated list of categories (this is how the OP does it). Quote Link to comment https://forums.phpfreaks.com/topic/301717-inserting-multiple-checkbox-values-into-a-single-mysql-database-column/#findComment-1536255 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.