douxiluan6555 2014-12-20 10:26
浏览 53
已采纳

将出勤单选按钮提交到数据库

am making this system and am stuck in a problm need help my database has table attandence where fields are att_id s_no std_reg_no std_name semester_id total_classes present absent i have made this form in which students of specific semester are displayed and radio buttons to mark whether a student is present or absent . i used s_no of students in the name of radio through an array following is the code

    <form method="POST" enctype="multipart/form-data" >
<input type="hidden" name="chk" value="update">
<table border="groove" cellpadding="15px">
<tr>
<td>s.no</td>
<td>Reg. No</td>
<td>name</td>
<td>Present</td>
</tr>

<?php
while ($row = mysql_fetch_assoc($rs)){
$id=  $row['s_no'];
$no[]=  $row['std_reg_no'];
echo "<tr><td>";
echo $row['s_no']."</td><td>";  
echo $row['std_reg_no']."</td><td>";
echo $row['std_name']."</td>";
echo "<td> <input type='radio' name='attend[$id]' value='present' >Present &nbsp; <input type='radio' name='attend[$id]' value='ab'>absent</td></tr>";
}

echo "</table>";
echo "<input type='submit' name='btnAbsent' value='submit'>";

echo a;
?>
</form>

what i want to do in php is to take each radiobutton if it is present add +1 to present and if absent +! to absent please someone help

  • 写回答

1条回答 默认 最新

  • doutangqi4444 2014-12-20 10:49
    关注

    Try this, i have increment +1 if you select any person as Present and i have decrement -1 if you have selected any person as Absent...

    Database table structure Query

    CREATE TABLE IF NOT EXISTS `attendance` (
      `att_id` varchar(255) NOT NULL,
      `s_no` varchar(255) NOT NULL,
      `std_reg_no` varchar(255) NOT NULL,
      `std_name` varchar(255) NOT NULL,
      `semester_id` varchar(255) NOT NULL,
      `total_classes` varchar(255) NOT NULL,
      `present` int(255) NOT NULL DEFAULT '0',
      `absent` int(255) NOT NULL DEFAULT '0'
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

    <form method="POST" enctype="multipart/form-data" >
    <input type="hidden" name="chk" value="update">
    <table border="groove" cellpadding="15px">
    <tr>
    <td>s.no</td>
    <td>Reg. No</td>
    <td>name</td>
    <td>Present</td>
    </tr>
    
    <?php
    include_once("yourconfig.php"); //add here your db config file
    extract($_POST);
    //After Click on Submit Call this
    if(isset($btnAbsent))
    {
        foreach($attend as $atn_key=>$atn_value)
        {
            if($atn_value=="present")
            {
                $upd_qry="UPDATE attendance SET present=present+1 where s_no='".$atn_key."'";
                mysql_query($upd_qry);
            }
            elseif($atn_value=="absent")
            {
                $upd_qry="UPDATE attendance SET absent=absent-1 where s_no='".$atn_key."'";
                mysql_query($upd_qry);
            }
        }
    }
    
    
    //Default call this
    $check_exist_qry="select * from attendance";
    $rs=mysql_query($check_exist_qry);
    $total_found=mysql_num_rows($rs);
    while ($row = mysql_fetch_assoc($rs))
    {
        $id=  $row['s_no'];
        $no[]=  $row['std_reg_no'];
        echo "<tr><td>";
        echo $row['s_no']."</td><td>";  
        echo $row['std_reg_no']."</td><td>";
        echo $row['std_name']."</td>";
        echo "<td> <input type='radio' name='attend[$id]' value='present' >Present &nbsp; <input type='radio' name='attend[$id]' value='absent'>absent</td></tr>";
    }
    
    echo "</table>";
    echo "<input type='submit' name='btnAbsent' value='submit'>";
    ?>
    </form>

    enter image description here

    if you found this is a helpful than give this answer as a correct and give vote for this solution

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏