gpt4 book ai didi

php - 复选框值插入空白?

转载 作者:行者123 更新时间:2023-11-30 00:23:56 27 4
gpt4 key购买 nike

我有一个程序,我想在其中插入根据复选框值动态生成的复选框值和图像字段。所有复选框名称和所有图像名称都相同。所有其他数据均已成功插入,但未插入复选框值。请帮我。我的 php 代码是:

<?php
include_once('connection.php');
$msg='';
$prod_imgs='';
if(isset($_REQUEST['submit']))
{
$category_id=$_REQUEST['category'];
$product_id=$_REQUEST['product'];
$relation_id=$_REQUEST['relation'];
$occasion_id=$_REQUEST['occasion'];
$prod_image = $_FILES['prod_image']['name'];
$tmp_prod_image=$_FILES['prod_image']['tmp_name'];
for($i=0;$i<count($prod_image);$i++)
{

if($prod_image[$i]!='')
{
$image="product_images/".$prod_image[$i];
//$occasion=$occasion_id[$i];
$insert=mysql_query("insert into tbl_add_product_occasion values('','$category_id','$product_id','$relation_id','$occasion_id','$image')");
if($insert)
{
$msg="your product info added successfully";
}
else
{
$msg="an error occur";
}
}
}
echo $msg;
}
?>

&html 代码是:

<script type="text/javascript">
function get_product(cat){
// alert(cat);
$.ajax({
type : "POST",
url : 'ajax_get_product.php',
data : 'cat=' +cat,
success : function(data){
//alert(data);
document.getElementById('prod').innerHTML=data;
//society_code').innerH''TML=data.d;
}
});

};


</script>
<form action="" method="post" enctype="multipart/form-data">

<fieldset>
<dl>
<dt><label for="gender">Select category:</label></dt>
<dd>
<select name="category" id="category" onchange="get_product(this.value)" >
<option>select category</option>
<?php
$sel=mysql_query("select * from tbl_category");
while($arr=mysql_fetch_array($sel))
{
$id=$arr['id'];
echo "<option value='".$id."'>".$arr['category']."</option>";
}
?>
</select>
</dd>
</dl>
<dl>
<dt><label for="product">Select Product:</label></dt>
<dd>
<select name="product" id="prod">
<option value=''>select product</option>

</select>
</dd>
</dl>

<dl>
<dt><label for="option">choose relation:</label></dt>
<dd>
<select name="relation">
<?php
$query=mysql_query("select * from tbl_relation");
while($result=mysql_fetch_array($query))
{
$relation=$result['relation'];
$relation_id=$result['id'];
echo "<option value='".$relation_id."'>".$relation."</option>";

}?>
s</select>
</dd>
</dl>
<dl>
<dt><label for="option">choose Occasion:</label></dt>
<div style="float:left;width: 400px;margin-top: 9px;">
<?php
$select=mysql_query('select * from tbl_occasion');
while($array=mysql_fetch_array($select))
{
$occasion_id=$array['id'];
?>


<dd style="width:auto;">
<span id="" style="width:115px; float:left;"><input type="checkbox" name="occasion[]" value="<?php echo $occasion_id;?>" /><?php echo $array['occasion'];?></span>
<input type="file" name="prod_image[]"/>

</dd>

<?php
}
?>
</div>
</dl>
<dl class="submit">
<input type="submit" name="submit" id="submit" value="Enter" />
</dl>
</fieldset>

</form>

请帮我解决这个问题。提前致谢..

最佳答案

尝试使用这个

<?php
include_once('connection.php');
$msg='';
$prod_imgs='';
if(isset($_REQUEST['submit']))
{
$category_id=$_REQUEST['category'];
$product_id=$_REQUEST['product'];
$relation_id=$_REQUEST['relation'];
$occasion=$_REQUEST['occasion'];
$prod_image = $_FILES['prod_image']['name'];
$tmp_prod_image=$_FILES['prod_image']['tmp_name'];
for($i=0;$i<count($prod_image);$i++)
{

if($prod_image[$i]!='')
{
$image="product_images/".$prod_image[$i];
$occasion_id=$occasion[$i];
$insert=mysql_query("insert into tbl_add_product_occasion values('','$category_id','$product_id','$relation_id','$occasion_id','$image')");
if($insert)
{
$msg="your product info added successfully";
}
else
{
$msg="an error occur";
}
}
}
echo $msg;
}
?>

关于php - 复选框值插入空白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23027235/

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