Thank you. It works fine with one column, when i use the following syntax:

insert into interest(username) values($game_name);

but is it possible to use it with more than one columns: for example if a user (david) has selected football and hockey:

username  |   football    |  soccer    |  hockey
david         |    football   |              |   hockey

do i have to use implode? what do i need?

kind regards m

>From: Martin Norland <[EMAIL PROTECTED]>
>Subject: Re: [PHP-DB] Re: checkbox into mysql using php <input type="checkbox"name="list
>Date: Thu, 17 Feb 2005 08:42:19 -0600
>Bastien Koert wrote:
>>if its all going into one col, then implode the array into a string
>>$data = implode(",",$_POST['games']);
>>Then insert the data. Still doesn't relieve you of the need to
>>validate the user data.
>No no no - you're confusing the guy further. He's taking an array
>post variable, foreaching it (resulting in a string in $value) and
>then using string indexes.
>$value == 'football'
>$value[0] == 'f'
>[unsnip - more to come]
>>>From: "moses Woldeselassie" <[EMAIL PROTECTED]>
>>>I did try that, but the input is going into one column or it is
>>>take the last array value and put it each chart in the table.
>>><input type="checkbox" name="games[]" value="football" />
>>>in that case, these are the value i got in mysql: f, o, o, t
>>> foreach($_POST['games'] AS $game => $value)
>>> $valuecount = count($_POST['games']);
>>> for($i =0; $i < $valuecount; $i++)
>>>$sql = mysql_query("insert into interest
>what he wants is (I think):
>foreach($_POST['games'] AS $game_name) {
> $sql = mysql_query("insert into interest values('$game_name');");
>or something similar. The idea is that they check 3 boxes for
>football, soccer, and hockey - and it inserts three rows into the
>database. It seems like we want to be inserting more than just the
>game though - surely the user it's associated with / etc.
>Moses - be sure to use curly brackets {} around blocks. Your above
>code only runs the "$valuecount = " bit inside the foreach, which
>is why you were spared it running 'squared' times (e.g. 2 games = 4
>times, 3 = 9, 4 = 16). The foreach and the for($i= code above are
>both there to accomplish the same thing, but $value stores the last
>seen value, so it would have looked as if you were still inside the
>foreach's scope. Stick with the foreach imo, since you don't need
>the counter. (you can get it back by using your foreach, the
>counter is the "$game =>" part - in my example I left it out since
>it's unnecessary.
>- Martin Norland, Sys Admin / Database / Web Developer,
>International Outreach x3257
>The opinion(s) contained within this email do not necessarily
>represent those of St. Jude Children's Research Hospital.
>PHP Database Mailing List (
>To unsubscribe, visit:

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to