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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?