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 <martin.norland@xxxxxxxxxx>
>Reply-To: php-db@xxxxxxxxxxxxx
>To: php-db@xxxxxxxxxxxxx
>Subject: Re: 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.
>>
>>Bastien
>[snip]
>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'
>etc.
>[unsnip - more to come]
>>>From: "moses Woldeselassie" <mmoses@xxxxxxxxxxx>
>>>
>>>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
>>>values('$value[0]','$value[1]','$value[2]','$value[3]')");
>[snip]
>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.
>
>Cheers,
>--
>- 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 (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
>
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php