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条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路