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

图片转代码服务由CSDN问答提供 功能建议

正在制作这个系统并且陷入问题需要帮助 数据库有表格attandence其中字段是 < code> att_id s_no std_reg_no std_name semester_id total_classes 现在 缺席 i已经制作了这个表格,其中显示了特定学期的学生和用于标记学生是否在场的单选按钮。 我通过数组使用无线电名称的学生的s_no代码

 &lt; form method =“POST”enctype =“multipart / form-data”&gt;  
&lt; input type =“hidden”name =“chk”value =“update”&gt; 
&lt; table border =“groove”cellpadding =“15px”&gt; 
&lt; tr&gt; 
&lt; td&gt; s.no&lt  ; / TD&GT; 
&LT; TD&GT;注册。 否&lt; / td&gt; 
&lt; td&gt;名称&lt; / td&gt; 
&lt; td&gt;提交&lt; / td&gt; 
&lt; / tr&gt; 
 
&lt;?php 
while($ row = mysql_fetch_assoc($ rs))  {
 $ id = $ row ['s_no']; 
 $ no [] = $ row ['std_reg_no']; 
echo“&lt; tr&gt;&lt; td&gt;”; 
echo $ row ['s_no'  ]。 “&LT; / TD&GT;&LT; TD&gt;” 中;  
echo $ row ['std_reg_no']。“&lt; / td&gt;&lt; td&gt;”; 
echo $ row ['std_name']。“&lt; / td&gt;”; 
echo“&lt; td&gt;&lt; input  type ='radio'name ='attend [$ id]'value ='present'&gt; Present&amp; nbsp;&lt; input type ='radio'name ='attend [$ id]'value ='ab'&gt; 缺席&lt; / td&gt;&lt; / tr&gt;“; 
} 
 
echo”&lt; / table&gt;“; 
echo”&lt; input type ='submit'name ='btnAbsent'value ='submit'&gt;  “; 
 
echo a; 
?&gt; 
&lt; / form&gt; 
   
 
 

我想在php中做的是采取每个单选按钮,如果它 存在加+1现在和如果缺席+! 请不要有人帮助

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

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>
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题