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 values('$value[0]','$value[1]','$value[2]','$value[3]')");
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:

Reply via email to