Hi All,
I have a form that I am getting an array of checkbox values and inserting them, but the first value should be "1" and I keep getting "11."
Here is my form value for the checkboxes...
<input name="Contacts[]" value="1"> Don
<input name="Contacts[]" value="4"> Christina
<input name="Contacts[]" value="2"> Len
<input name="Contacts[]" value="5"> Candy
<input name="Contacts[]" value="6"> Rick
<input name="Contacts[]" value="3"> Tara
and my PHP loop to get the data and insert it...
$dbname = 'table';
mysql_select_db ($dbname, $conn) or die (mysql_error());
$xx=0;
foreach($_POST['Contacts'] as $contact) {
$contact.$xx = $contact[$xx];
echo '$contact.$xx ='.$contact.$xx.'& $contact[$xx]='.$contact[$xx].'<br />';
$sql ="insert into table";
$sql .="(contactid, joborderid, misc) ";
$sql .="values ('$contact".$xx."', '$id', NULL)";
echo $sql.'<br />';
$xx++;
}
But heres the results (including a print_r of the POST array)...
Array
(
[Creative] => 1
[Contacts] => Array
(
[0] => 1
[1] => 4
[2] => 2
[3] => 5
[4] => 6
[5] => 3
)
[url] => http://www.somewhere.com
[description] => yadda
[Submit] => Submit
)
$contact.$xx =11& $contact[$xx]=
insert into assigned (contactid, joborderid, misc) values ('11', '8', NULL)
$contact.$xx =4& $contact[$xx]=4
insert into assigned (contactid, joborderid, misc) values ('4', '8', NULL)
$contact.$xx =2& $contact[$xx]=2
insert into assigned (contactid, joborderid, misc) values ('2', '8', NULL)
$contact.$xx =5& $contact[$xx]=5
insert into assigned (contactid, joborderid, misc) values ('5', '8', NULL)
$contact.$xx =6& $contact[$xx]=6
insert into assigned (contactid, joborderid, misc) values ('6', '8', NULL)
$contact.$xx =3& $contact[$xx]=3
insert into assigned (contactid, joborderid, misc) values ('3', '8', NULL)
Note the values above in red, that "$contact[$xx]=" has no initial value and that the insert is then "11" instead of "1" .
Where did my code go south, so to speak?
Thanks in advance,
Don