我有一个程序,我想在其中插入复选框值&根据复选框值动态生成的图像字段。所有复选框名称&所有图像名称都相同。所有其他数据都已成功插入,但未插入复选框值。请帮我。我的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>
请帮我解决这个问题。 提前谢谢..
答案 0 :(得分:0)
尝试使用此
<?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;
}
?>