Insert an array into MySQL

From: Date: Sun, 23 Jun 2002 11:49:31 +0000
Subject: Insert an array into MySQL
Groups: php.general 
Request: Send a blank email to php-general+get-103453@lists.php.net to get a copy of this message
Hi, I've seen a few post for this same thing but I can't seem to get it working. What I'm doing is taking a form with check boxes and putting them into an array. Then I'm attempting to INSERT them into the db, one checkbox value per row. Okay, well I've tries 2 ways that I think should work and they only insert the first value. They both produce this error "Duplicate entry '0' for key 1" (which I don't understand) Anyway here is the code I'm trying... (I'm not trying to use both blocks of code, just one or the other) // First code while(list($key,$value)=each($pagetype)){ //echo $value."<br>";//test $links="INSERT INTO $username_links (links) VALUES ('$value')"; $insert=mysql_query($links,$connection); } // Second code attempt $number=count($pagetype); for($a=0;$a<$number;$a++){ $links="INSERT INTO $username_links (links) VALUES ('$pagetype[$a]')"; $insert=mysql_query($links) or die(mysql_error()); //echo $pagetype[$a];//test } Thanks in advance...Robert

« previous php.general (#103453) next »