Passing arrays via checkboxes
Posted: Mon Sep 14, 2009 10:40 am
I'm stumped. I've been at this for days!! Huh
I'm trying to pass an array via checkboxes, using php and mysql. I have the following 2 pages, can someone please tell me what I've got wrong. I can pass the array to the second page, and have it echo(print) correctly, but when it gets to the database, it will only give me the last choice. I also can get it to post "array" to the database, but I don't want that either!!
Insert form:
Results Action page
I'm trying to pass an array via checkboxes, using php and mysql. I have the following 2 pages, can someone please tell me what I've got wrong. I can pass the array to the second page, and have it echo(print) correctly, but when it gets to the database, it will only give me the last choice. I also can get it to post "array" to the database, but I don't want that either!!
Insert form:
Code: Select all
<?php
echo "<form method=post action='form3.php'>";
echo "<table border='0' cellspacing='0' style='border-collapse: collapse' width='100' >
<tr bgcolor='#ffffff'>
<td width='25%'><input type=checkbox name=providers[] value='BlueCross BlueShield'></td>
<td width='25%'> BlueCross BlueShield</td>
<td width='25%'><input type=checkbox name=providers[] value='HealthPartners'></td>
<td width='25%'> HealthPartners</td>
<td width='25%'><input type=checkbox name=providers[] value='PreferredOne'></td>
<td width='25%'> PreferredOne</td>
</tr>
<tr><td colspan =6 align=center><input type=submit value=Select></form></td></tr>
</table>"; ?>Code: Select all
<?php
$providers=$_POST['providers'];
while (list ($key,$val) = @each ($providers)) {
echo "$val,\n";
$mysql="INSERT INTO oe.hsa SET
providers='$val'";}
if (@mysql_query($mysql)) {
echo 'New Registration added';
} else {
echo mysql_error();
}
?>