gpt4 book ai didi

php - 如何使用ajax在数据库中插入复选框值......我正在尝试下面的代码不工作

转载 作者:行者123 更新时间:2023-11-29 22:29:28 25 4
gpt4 key购买 nike

表格:

<?php     foreach($db->query("SELECT * FROM `company_details` WHERE id='$userid' LIMIT 1 ") as $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);
});

});

以下代码位于ajax.php

//for manufactures where cid='$userid'  AND 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' WHERE cid='$userid' AND categories='Manufaturers'");
foreach($_POST['Basic_Amenities'] as $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 You ..Your details submitted sucessfully <br> Your Profile Will Be Activated Soon ..!!</div>
</div>';
exit();
}
else{
echo '<div style="color:red;">business details not submitted</div>';
}

}

最佳答案

脚本标记丢失。尝试这个。

 <?php     foreach($db->query("SELECT * FROM `company_details` WHERE id='$userid' LIMIT 1 ") as $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>

关于php - 如何使用ajax在数据库中插入复选框值......我正在尝试下面的代码不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29937578/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com