Hello
can someone please help me, I am trying to add information to a database with checkbox. I have every thing working expect for the checkbox. I am fairly new to the php/sql side of web coding. Anyway I want to add information to the one field of a database, in this case fruit. When I click submit it show the information as array, but I want it to be displayed as the value, eg banana, apple not as Array.
<form action="script/test.php" method="post">
<table>
<TD><input type="checkbox" name="fruit[]" id='fruit[]' value='banana'>
banana</TD>
<TD><input type="checkbox" name="fruit[]" id='fruit[]' value='apple'>
Apple</TD>
</tr>
<tr>
<TD></TD>
<TD><input type="checkbox" name="fruit[]" id='fruit[]' value='pine'>
Pineapple</TD>
<TD><input type="checkbox" name="fruit[]" id='fruit[]' value='other'> Other</TD>
<tr></tr>
<tr>
</TABLE></form
Php code
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$sql="INSERT INTO food (Fruit)
VALUES
('$_POST[fruit]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "information has been added";
mysql_close($con)
?>