php - POST values from dynamically created radio buttons to mysql database -
i have sets of radio buttons fetched database. data tables -
id title name option1 option2 option3 ------ ------- ------- ------- ------- ---------- 1 wi-fi wifi yes no (null) 4 parking parking yes no optional
i have following codes fetch data database.
$get_biz_meta_list = mysqli_query($connect, "select * biz_meta_list") <form class="form-horizontal" action="add-biz-meta.php" role="form" method="post" > <?php while($biz_meta_list = mysqli_fetch_array($get_biz_meta_list,mysql_assoc)){ ?> <input type="hidden" name="mid" value="<?php echo $biz_meta_list['id'];?>" /> <div class="form-group col-md-12"> <label for="inputemail1" class="col-md-3 control-label"><?php echo $biz_meta_list['title'];?></label> <div class="col-md-2"> <input type="radio" name=meta[<?php echo $biz_meta_list['id'];?>] value="<?php echo $biz_meta_list['option1'];?>"/><?php echo $biz_meta_list['option1'];?> </div> <div class="col-md-2"> <input type="radio" name=meta[<?php echo $biz_meta_list['id'];?>] value="<?php echo $biz_meta_list['option2'];?>"/><?php echo $biz_meta_list['option2'];?> </div> <?php if($biz_meta_list['option3']!==null){ ?> <div class="col-md-2"> <input type="radio" name=meta[<?php echo $biz_meta_list['id'];?>] value="<?php echo $biz_meta_list['option3'];?>"/><?php echo $biz_meta_list['option3'];?> </div> <?php } ?> </div> <?php } ?> <div class="form-group"> <div class="col-md-offset-5 col-md-6"> <input type="submit" class="btn btn-primary" value="save" name="savemeta" /> </div> </div> </form>
then after submitting post selected fields table. means if select "yes
" "wi-fi
" "title
" , "option1
" saved database. if both "wi-fi
" , "parking
" selected both values stored in separate row. tried catch value this-
if(isset($_post['savemeta'])){ foreach ($_post['meta'] $meta){ $meta_name = get_meta_name($meta,$connect); echo $meta_name; } }
$get_meta_name custom function retrun title.
but showing blank in post echo. please me.
you miss quotes in radio button name attribute. when loop on $_post['meta'], lose index id of option. don't know get_mena_name function does, don't know how return 'name', because $meta contains 'yes' or 'no' values.
correct radio button quotes
name="meta[<?php echo $biz_meta_list['id'];?>]"
and php this:
foreach ($_post['meta'] $id=>$value){ //do stuff id , value $meta_name = get_meta_name($id,$connect); echo $meta_name; }
Comments
Post a Comment