JPark Posted February 17, 2009 Share Posted February 17, 2009 If I have a form with checkboxes, such as: <form action="foo.php" method="post"> <input type="checkbox" name="bar[]" value="one" /> One<br /> <input type="checkbox" name="bar[]" value="two" /> Two<br /> <input type="checkbox" name="bar[]" value="three" /> Three<br /> <input type="checkbox" name="bar[]" value="four" /> Four<br /> <input type="checkbox" name="bar[]" value="five" /> Five<br /> <br /> <input type="submit" value="Check checks" /> </form> and a client clicks on One, Two and Three and hits Submit, I want to put this data into my MySQL database. As it stands, when I capture $bar=$_POST['bar'] and go to submit my query, $query = "INSERT INTO database VALUES ('', '$bar'); and then echo my $query, I get INSERT INTO database VALUES ('', 'Array') Question: How do I post (and retrieve) the individual values ("one", "two" and "three") as opposed to 'Array'? Thanks! Joe Link to comment https://forums.phpfreaks.com/topic/145609-forms-arrays-mysql/ Share on other sites More sharing options...
allworknoplay Posted February 17, 2009 Share Posted February 17, 2009 You can serialize the array before you put it into the DB. Link to comment https://forums.phpfreaks.com/topic/145609-forms-arrays-mysql/#findComment-764444 Share on other sites More sharing options...
JPark Posted February 18, 2009 Author Share Posted February 18, 2009 But if I don't and the Array is sent to the db, when I draw it out, all the various items that make up the Array can be brought out with $serializebar = serialize($bar); $arr = unserialize(urldecode($bar)); var_dump($arr); right? Link to comment https://forums.phpfreaks.com/topic/145609-forms-arrays-mysql/#findComment-765158 Share on other sites More sharing options...
tjohnson_nb Posted February 18, 2009 Share Posted February 18, 2009 Question: How do I post (and retrieve) the individual values ("one", "two" and "three") as opposed to 'Array'? How about? foreach ($_POST['bar'] as $value) { $query = "INSERT INTO database VALUES ('', '$value'); } Link to comment https://forums.phpfreaks.com/topic/145609-forms-arrays-mysql/#findComment-765183 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.