Query in Php/ Mysql Code!!

No replies
programmer
Offline
Last seen: 10 years 33 weeks ago
Joined: 2009-04-14
bOt Points: 86

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 CODE

<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

  1. $con = mysql_connect("localhost","root","");
  2. if (!$con)
  3. {
  4. die('Could not connect: ' . mysql_error());
  5. }
  6.  
  7. mysql_select_db("test", $con);
  8.  
  9. $sql="INSERT INTO food (Fruit)
  10. VALUES
  11. ('$_POST[fruit]')";
  12.  
  13. if (!mysql_query($sql,$con))
  14. {
  15. die('Error: ' . mysql_error());
  16. }
  17. echo "information has been added";
  18.  
  19. mysql_close($con)
  20. ?>