php - How to insert the checkbox value in database using ajax...... i am trying below code not not working -
form:
<?php foreach($db->query("select * `company_details` id='$userid' limit 1 ") $edit) { echo '<form class="form-horizontal" id="productdetail_form" name="productdetail_form" method="post" style="padding:20px 0;"> <input type="hidden" name="productdetail_formhide" id="productdetail_formhide" value="productdetail_formhide"/> <input type="hidden" name="productdetail_city" id="productdetail_city" value="'.$edit['city'].'"> <input type="hidden" name="cid" id="cid" value="'.$userid.'"> <input type="hidden" name="productdetail_cname" id="productdetail_cname" value="'.$edit['comp_name'].'">';}?> <h2>manufacture</h2> <div class="row"><div class="col-sm-4" > <label class="checkbox-inline no_indent"> <input type="checkbox" class="check" id="basic_amenities" name="basic_amenities[]" value="water sports equipment" />water sports equipment </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" class="check" id="basic_amenities" name="basic_amenities[]" value="adventure sports" />adventure sports </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" class="check" id="basic_amenities" name="basic_amenities[]" value="billiard/snooker/polls"/>billiard/snooker/polls </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" class="check" id="basic_amenities" name="basic_amenities[]" value="gym fitness equipment" >gym fitness equipment </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" class="check" id="basic_amenities" name="basic_amenities[]" value="medal trophy" >medal trophy </label> </div> <div class="col-sm-4"> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="playground equipment" >playground equipment </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports bags" >sports bags </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports apprarels" >sports apprarels </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports bikes / cycles" >sports bikes / cycles </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports goods" >sports goods </label> </div> <div class="col-sm-4"> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports nutrition" >sports nutrition </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports wear fabric">sports wear fabric </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports flooring" >sports flooring </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports shoes">sports shoes </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports raw materials" >sports raw materials </label></br> <div class="form-group"> <label for="name" class="col-sm-2 control-label"></label> <div class="col-sm-10 text-center"> <input type="submit" id="productdetail_submit" name="productdetail_submit" value="submit product details" class="btn btn-success"> </div> </div> </div> </div> </form> ?> $( "#productdetail_form" ).submit(function( event ) { event.preventdefault(); var productdetail_formhide = $("#productdetail_formhide").val(); var productdetail_cid = $("#cid").val(); var productdetail_cname = $("#productdetail_cname").val(); var basic_amenities= new array(); var basic_amenities = new array(); $("#manufacture :checkbox:checked").each(function() { basic_amenities.push($(this).val()); }); var productdetail_city = $("#productdetail_city").val(); var manufacture = $("a[name=tab1]").data("index"); $("#productdetail_form").empty(); alert(basic_amenities); alert(manufacture); $("#productdetail_form").prepend('<div id="productdetail" style="color:red;">submitting data..... please wait.. </div>'); $.post("merchant/edit_ajax.php", { productdetail_formhide:productdetail_formhide, productdetail_cid:productdetail_cid, productdetail_cname:productdetail_cname, basic_amenities:basic_amenities, productdetail_city:productdetail_city, manufacture:manufacture, }, function(data,status){ $("#productdetail").hide(); $("#productdetail_form").prepend(data); }); });
below code on ajax.php
//for manufactures cid='$userid' , categories='manufaturers' if(isset($_post['productdetail_formhide'])=='productdetail_formhide'){ $q = $db->prepare("update `business_category` set cid=:cid, comp_name=:comp_name, categories=:categories, subcategories=:subcategories, city=:city ,activation='0' cid='$userid' , categories='manufaturers'"); foreach($_post['basic_amenities'] $basic){ $q->execute(array(':cid'=>$_post['cid'].'', ':comp_name'=>$_post['productdetail_cname'].'', ':categories'=>$_post['manufacture'].'', ':subcategories'=>$basic.'', ':city'=>$_post['productdetail_city'].'')); } if($q==true){ echo '<div align="center" > <div style="color:green;"> thank ..your details submitted sucessfully <br> profile activated ..!!</div> </div>'; exit(); } else{ echo '<div style="color:red;">business details not submitted</div>'; } }
script tag missing. try this.
<?php foreach($db->query("select * `company_details` id='$userid' limit 1 ") $edit) { echo '<form class="form-horizontal" id="productdetail_form" name="productdetail_form" method="post" style="padding:20px 0;"> <input type="hidden" name="productdetail_formhide" id="productdetail_formhide" value="productdetail_formhide"/> <input type="hidden" name="productdetail_city" id="productdetail_city" value="'.$edit['city'].'"> <input type="hidden" name="cid" id="cid" value="'.$userid.'"> <input type="hidden" name="productdetail_cname" id="productdetail_cname" value="'.$edit['comp_name'].'">';}?> <h2>manufacture</h2> <div class="row"><div class="col-sm-4" > <label class="checkbox-inline no_indent"> <input type="checkbox" class="check" id="basic_amenities" name="basic_amenities[]" value="water sports equipment" />water sports equipment </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" class="check" id="basic_amenities" name="basic_amenities[]" value="adventure sports" />adventure sports </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" class="check" id="basic_amenities" name="basic_amenities[]" value="billiard/snooker/polls"/>billiard/snooker/polls </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" class="check" id="basic_amenities" name="basic_amenities[]" value="gym fitness equipment" >gym fitness equipment </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" class="check" id="basic_amenities" name="basic_amenities[]" value="medal trophy" >medal trophy </label> </div> <div class="col-sm-4"> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="playground equipment" >playground equipment </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports bags" >sports bags </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports apprarels" >sports apprarels </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports bikes / cycles" >sports bikes / cycles </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports goods" >sports goods </label> </div> <div class="col-sm-4"> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports nutrition" >sports nutrition </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports wear fabric">sports wear fabric </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports flooring" >sports flooring </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports shoes">sports shoes </label><br/> <label class="checkbox-inline no_indent"> <input type="checkbox" id="basic_amenities" name="basic_amenities[]" value="sports raw materials" >sports raw materials </label></br> <div class="form-group"> <label for="name" class="col-sm-2 control-label"></label> <div class="col-sm-10 text-center"> <input type="submit" id="productdetail_submit" name="productdetail_submit" value="submit product details" class="btn btn-success"> </div> </div> </div> </div> </form> <script> $( "#productdetail_form" ).submit(function( event ) { event.preventdefault(); var productdetail_formhide = $("#productdetail_formhide").val(); var productdetail_cid = $("#cid").val(); var productdetail_cname = $("#productdetail_cname").val(); var basic_amenities= new array(); var basic_amenities = new array(); $("#manufacture :checkbox:checked").each(function() { basic_amenities.push($(this).val()); }); var productdetail_city = $("#productdetail_city").val(); var manufacture = $("a[name=tab1]").data("index"); $("#productdetail_form").empty(); alert(basic_amenities); alert(manufacture); $("#productdetail_form").prepend('<div id="productdetail" style="color:red;">submitting data..... please wait.. </div>'); $.post("merchant/edit_ajax.php", { productdetail_formhide:productdetail_formhide, productdetail_cid:productdetail_cid, productdetail_cname:productdetail_cname, basic_amenities:basic_amenities, productdetail_city:productdetail_city, manufacture:manufacture, }, function(data,status){ $("#productdetail").hide(); $("#productdetail_form").prepend(data); }); }); </script>
Comments
Post a Comment