checkbox array and inserting into db

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
incyte
Forum Newbie
Posts: 7
Joined: Sun Jul 25, 2004 7:33 pm

checkbox array and inserting into db

Post 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
?>
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Code: Select all

serialize();
Serialize

Code: Select all

#in ure case that would become
$athletics = serialize($_POST['sport']);
#-> and the query
incyte
Forum Newbie
Posts: 7
Joined: Sun Jul 25, 2004 7:33 pm

still problems

Post 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
incyte
Forum Newbie
Posts: 7
Joined: Sun Jul 25, 2004 7:33 pm

nevermind

Post 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
Post Reply