duanliang8464 2014-12-10 13:01
浏览 56
已采纳

如何在从数据库检索的表中使用单选按钮并将值存储在另一个表中

i am trying to make an attendance chart in php. i wish to increment the counter of attendance in the database on click of a radio button. how do i retrieve the value and then increment for every "yes"?

do i need to put the updation code in the next page?

i tried it that way..but the fields are not getting updated..

if($class=="cse")
    {
        $result = mysqli_query($con, "SELECT * FROM cse");
        echo "<table border=15px cellspacing=40>";
        echo "<tr><th>NAME</th><th>BUPIN</th><th>ATTENDANCE</th></tr>";
        while ($row = mysqli_fetch_array($result)) 
    {
        echo "<tr><td>" . $row["name"] . "</td>" . "<td>" . $row["bupin"] . "</td>";
        echo "<td>" . "<input type='radio' name='presence[".$row["bupin"]."]' value='yes'>Yes";
        echo "<input type='radio' name='presence[".$row["bupin"]."]' value='no'>No" . "</td></tr>";
    }
    echo "</table>";
    ?>
    <html>
    <form action= "final6.php" method="POST">
    <input type="Submit" value="Submit">
    </form>
    </html>
    }}

and the next page code is as:if (isset($_POST["presence"])) { foreach ($presence as $key => $val) { if ($val == 'yes') { $sql = "UPDATE cse SET 1attendance = 1attendance + 1 WHERE bupin = " .$key; msyqli_query($con, $sql); } } } echo "Attendance marked successfully.."; }

where am i wrong?

  • 写回答

1条回答 默认 最新

  • dongyanzhui0524 2014-12-10 13:08
    关注

    If the bupin the primary key (id) in your table cse, then try this. Of course, change the field in the query to your field, what you want to incrase.

    $result = mysqli_query($con, "SELECT * FROM cse");
    echo "<table border=15px cellspacing=40>";
    echo "<tr><th>NAME</th><th>BUPIN</th><th>ATTENDANCE</th></tr>";
    while ($row = mysqli_fetch_array($result)) {
        echo "<tr><td>" . $row["name"] . "</td>" . "<td>" . $row["bupin"] . "</td>";
        echo "<td>" . "<input type='radio' name='presence[".$row["bupin"]."]' value='yes'>Yes";
        echo "<input type='radio' name='presence[".$row["bupin"]."]' value='no'>No" . "</td></tr>";
    }
    echo "</table>";
    
    
    if (isset($_POST["presence"])) {
        foreach ($presence as $key => $val) {
            if ($val == 'yes') {
                $sql = "UPDATE cse SET field = field + 1 WHERE bupin = " . $key;
                msyqli_query($con, $sql);
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分