hi
you need to use implode() php function for convert string
for e.g
$fruits=$_POST[fruit];
$fruits_str=implode(',',$fruits);//it seprates value by comma
$fruits_str=implode(' ',$fruits);//it seprates value by space
I hope this function help you to solve problem
Thanks
Tulsa
Junior Poster in Training
77 posts since May 2009
Reputation Points: 13
Solved Threads: 15
Welcome mccs.
This is your first post and it is very impressive.
You missed Submit Button and also "fruits" is an array and its elements should be written into a table.
<?php
$cmd=$_REQUEST["cmd"];
// If submit button is pressed
if(isset($cmd)) {
$con = mysql_connect("localhost","root","");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("test", $con);
$fruit=$_REQUEST["fruit"]; // array of checked box values
foreach($fruit as $i) {
$sql="INSERT INTO food (Fruit) VALUES ('$i')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
}
echo "information has been added";
mysql_close($con);
}
?>
<form action="script/test.php" method="post">
<table>
<tr>
<td>
<input type="checkbox" name="fruit[]" id='fruit[]' value='banana'>
banana
</td>
<tr>
<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>
<tr>
<td>
<input type="submit" name="cmd" value="Submit"/>
</td>
</tr>
</table>
</form>
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241