send checkbox value(s) to mysql using php?

ApurvA

New member
JAI MATADI all ..

m trying to send selected value(s) into mysql using php .. but m getting problem in this .. here is my code ..

------------------------
mytry.php
--------------
<form name="f1" method="post" >
<p>Select Your Product(s) :
<br />
</p>

<p><br />


<input name="c1[]" type="checkbox" value="Product1" />
Product1
<input name="c1[]" type="checkbox" value="Product2" />
Product2
<input name="c1[]" type="checkbox" value="Product3" />
Product3
<input name="c1[]" type="checkbox" value="Product4" />
Product4

<br />
<br />
<input type="submit" name="submit" />
</p>
</form>
<?php

if(isset($_POST["submit"]))
{

$box = @$_POST['c1'];

while (list ($key,$val) = @each ($box))
{
mysql_connect("localhost","root","");
mysql_select_db("checkboxdatabase");
$qry = "insert into table1 (inquiry) values('$val')";
if(mysql_query($qry))
{
echo "Inserted";

}
else
{
echo mysql_error();
}

echo "$val,";

}


}

?>
-----------------------------

the problem m facing here is if m selecting nothing its not inserting anything and if m selecting Product1, Product2 etc . its inserting twice as many times as per i selected the products ..

how can i solve this problems .. how can i send values in the same column not twice or many times ..

plzz tell me .. i really need it ..

thanks in advance . .
 
Back
Top