Page 1 of 1

Insert array into rows

Posted: Sun Jun 23, 2002 7:19 am
by Robert
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

Posted: Sun Jun 23, 2002 2:27 pm
by will
how is your links table set up...what fields does it have? do you have any kinda of unique id to identify the row with?

I got it

Posted: Sun Jun 23, 2002 2:44 pm
by Robert
Yep, I had a Unique field (doh!). Thanks.

Robert :)