<form action="message1.php" method="post" >
<img height="150" width="200"src="<?php echo $images_dir."/tb_".$row[2]; ?>"/><input type='checkbox' name='chk1[]' value ='<?php echo basename($images_dir."/".$row[2]);?>'/><input type='text' name='textbox[]'id='textbox'/> </br>
$checkbox1=$_POST['chk1'];
$txt =$_POST['textbox'];
if($_POST["submit"]=="submit") {
for($i=0;$i<sizeof($checkbox1);$i ) {
if(!empty($txt)) {
$ query =“INSERT INTO message(item,quantity)VALUES('”。$ checkbox1 [$ i]。“','”。$ txt。“')”; mysql_query($ query)或die(mysql_error()); } } echo“message is send”;
答案 0 :(得分:0)
如果要从同一个复选框组发布多个值,则必须按照数组中的复选框字段 type ='checkbox'name ='chk1 []'当您发布该值时,请使用以下代码
for($i=0;$i<count($_POST['chk1']);$i++) {
$checkval = $checkval.",".$_POST['chk1'][$i];
}
echo $checkval;
我希望我回答你的问题。
由于
答案 1 :(得分:0)
$checkbox1=$_POST['chk1'];
if(!empty($_POST['chk1']))
{
$txt = $checkbox1;
}
else
{
$txt =$_POST['textbox'];
}
if($_POST["submit"]=="submit") {
for($i=0;$i<sizeof($checkbox1);$i++) {
if(!empty($txt)) {
$query="INSERT INTO message(item,quantity) VALUES('".$checkbox1[$i]."','".$txt[$i]."')";
mysql_query($query) or die(mysql_error());
}
}
echo "message is send";
}
答案 2 :(得分:0)
<?php
if(isset($_POST['submit']))
{
if(!empty($_POST['name1']))
{
$name1=implode(",",$_POST['name1']);
if(!empty($_POST['name']))
{
$name=$_POST['name'];
$name = $name .','. $name1;
}
else
{
$name=$name1;
}
}
else
{
$name =$_POST['name'];
}
$conn=mysqli_connect('localhost','root','','test');
$sql=mysqli_query($conn,"insert into t values('$name')");
if($sql)
{
echo "Inserted!!";
}
else
{
echo "Failed to insert!!";
}
}
?>