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);
            }
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容