php - how to add checkbox intems in to data base in one row -


i crated form,

<td>                <input type="checkbox" name="mode[]" id="mode" value="sweet" />                      sweet<br />                     <input type="checkbox" name="mode[]" id="mode" value=" sour" />                        sour<br />                     <input type="checkbox" name="mode[]" id="mode" value=" creamy" />                        creamy<br />                       <input type="checkbox" name="mode[]" id="mode" value="bland" />                       bland<br />                                 </td> 

and php code is,

for ($i=0; $i<sizeof($mode); $i++) {     $emode = mysql_real_escape_string($mode[$i]);      $query  =<<<eof insert frutesdetails(fruitname,fruitcolor,seasonfrom,seasonto,fruitetaste,fruitbenefit)  values ('{$fruitname}', '{$category}',         '{$startdate}','{$enddate}','{$emode}','{$fruitbenefit}') eof; $insertresults = mysql_query($query) or die(mysql_error());   } 

i got record not in 1 recod ,if check 2 check box 2 records in 2 different row not in single row

if want stored in 1 record, first remove for() loop. have couple options take pick:

$emode = mysql_real_escape_string(json_encode($mode)); $emode = mysql_real_escape_string(serialize($mode)); $emode = mysql_real_escape_string(implode(',',$mode)); 

then have decode on way out.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -