doujing4555 2014-04-09 13:56
浏览 94
已采纳

如何创建具有多个复选框的html表单

This is my code for creating an html form that reads from a database and will allow the user to check and uncheck boxes for each of the 640 items. This is the form.php:

// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

// see if any rows were returned 
if (mysql_num_rows($result) > 0) { 
    // yes 
    // print them one after another 
    echo "<html><body>  <table cellpadding=10 border=1>"; 
    while($row = mysql_fetch_assoc($result)) { 
        echo "<tr>"; 
        echo "<td>".$row['stickerID']."</td>"; 
        echo "<td>" .$row['stickerName']."</td>"; 
        echo "<td>".$row['stickerSection']."</td>"; 
        echo "<td>"?>
                 <form name="some form" action="editform.php" method="post">
                 <input type="checkbox" name="<?php echo $row['stickerID'] ?>" value=" <?php echo $row['stickerStatus'] ?> ">
                 <?php "</td>";
        echo "</tr>"; 
    }
    echo "</table></body></html>";
    echo " " ?>
                 <input type="submit" name="editWish" value="Edit">
                 </form>
                 <?php " ";
} else { 
    // no 
    // print status message 
    echo "No rows found!"; 
} 

The user must then be able to click on submit and have those values updated in the mysql database.

Right now when I click the submit button, it posts to edit form.php which has this:

<?php

//echo results
foreach($_POST['stickerID'] as $k=>$v ){
echo $k;
echo $v;
}

?>

But I don't get anything echoed. I was thinking the problem could be that Im actually creating a form for every row instead of 1 form with many rows/checkboxes. But when I move the form code after the and the tag to the line where line, I can't even load the form.php, it just loads blank.

Where is my problem? :) Thx

  • 写回答

2条回答 默认 最新

  • doutong6814 2014-04-09 14:01
    关注

    Name your checkbox like this:

    <input type="checkbox" name="stickerID[]" value=" <?php echo $row['stickerStatus']; ?> ">
    

    And as Amal already said update your code to PDO or MySQLi

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿