Page 1 of 1

checkbox array and inserting into db

Posted: Sun Jul 25, 2004 7:33 pm
by incyte
Sup all,

i was wondering if someone could help me out with these checkboxes. I followed the tutorials and things on other sites. Understood it a bit better from this site :), but still cant seem to get it to work right.

Code: Select all

<?php
           if (is_array($_POST['sport'])) {
	foreach ($_POST['sport'] as $athletics) {
	$sql = "INSERT INTO $table (athletics) VALUES ($athletics)";
	}
           }
?>
now i have another $sql above this for all the other database info. That all submits just not the athletics checkboxes. If i replace the $sql statement and put echo "$athletics<br>\n"; that will list the checkbox arrays.

What am i doin wrong :cry:

any help is appreciated
thanks
incyte
?>

Posted: Sun Jul 25, 2004 8:23 pm
by ol4pr0

Code: Select all

serialize();
Serialize

Code: Select all

#in ure case that would become
$athletics = serialize($_POST['sport']);
#-> and the query

still problems

Posted: Sun Jul 25, 2004 8:43 pm
by incyte
thanks it worked, inputed the checkbox values, now i know i just have to unserialize them. Now the rest of the information wont go in. haha...

tried putting $sql .= .... to add to the $sql above it but i get this error

You have an error in your SQL syntax near 'INSERT INTO student (athletics) VALUES ('a:2:{i:0;s:8:"baseball";i:1;s:4:"golf";' at line 21

nevermind

Posted: Sun Jul 25, 2004 8:53 pm
by incyte
nevermind

got everythign to work now.

thank you for your help put me on the right track after days of searching for answers.

what i did was put join(',',$_POST['sport'])

thanks again

incyte