php - $_POST from checkbox with the same name and different values -
this question has answer here:
i have sql database has table (results) gonna save of results of survey.
one of questions checkbox (multiple answer), made code should gather results of checkbox questions , put values database.
but, something's missing, overwrites last value in array there easy solution cannot see. clarify, want store values of 1 checkbox question if user checks everything.
html form
<input type="checkbox" name="checkbox1" value="this first value"> <input type="checkbox" name="checkbox1" value="this second value"> <input type="checkbox" name="checkbox1" value="this third value">
php script
for($i=1;$i<101;$i++) { if(isset($_post['checkbox'.$i])) { $q[$i] .= $_post['checkbox'.$i].'; '; }} <?php $db =& jfactory::getdbo(); $query = "insert jos_results(question1) values ('$q[1]')"; $db->setquery($query); $db->query(); ?>
if name of check box type same use array work. here
<input type="checkbox" name="checkbox1[]" value="this first value"> <input type="checkbox" name="checkbox1[]" value="this second value"> <input type="checkbox" name="checkbox1[]" value="this third value">
Comments
Post a Comment