Jump to content

Forms, arrays, MySQL


JPark

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.