2014-09-26 41 views
-3

該表中的值已從數據庫中生成,請參閱附加的圖像。現在我需要從表格中的複選框以及regno(註冊號)或名稱中獲取值。從這個PHP編碼我想要得到的複選框的值與regno。並插入到數據庫(mysql)

<form role="form" method="post"> 
      <label class="attendance"><strong>Date:</strong></label> 
      <strong> 
      <input name="date" id="date" /></strong> 
     </div> 
     <table align="left" width="100%"> 
     <tr> 
     <th>Rollno</th> 
     <th>Regno</th> 
     <th>Name</th> 
     <th>Status</th> 
     </tr> 
<?php 
$query = "SELECT * FROM student where course='M.Sc.Software Systems' and year='4' "; 
$result=mysql_query($query) or die("Query Failed : ".mysql_error()); 
while($rows=mysql_fetch_array($result)) 
{     
?> 
    <tr> 
    <td><?php echo $rows['rno'];?></td> // values of rollno from database 
    <td><?php echo $rows['regno']; ?></td> // values of regno from database 
    <td><?php echo $rows['name'];?></td> 
    <td> 
     <input type="checkbox" name="hour1" value="1"/> 
     <input type="checkbox" name="hour2" value="1"/> 
     <input type="checkbox" name="hour3" value="1"/> 
     <input type="checkbox" name="hour4" value="1"/> 
     <input type="checkbox" name="hour5" value="1" /> 
    </td> 
    </tr> 
<?php } ?> 
</table> 
    <button name='insert' type="submit" class="contact">Submit</button> 
    </form> 
<?php 
     if (isset($_POST['insert'])){ 
     $regno = $rows['regno1']; 
     $hour1 = $_POST['hour1']; 
     $hour2 = $_POST['hour2']; 
     $hour3 = $_POST['hour3']; 
     $hour4 = $_POST['hour4']; 
     $hour5 = $_POST['hour5']; 


     $query2 = "INSERT INTO attendance (regno,hour1,hour2,hour3,hour4,hour5) VALUES ('$regno','$hour1','$hour2','$hour3','$hour4','$hour5')"; 
     $result2=mysql_query($query2) or die("Query Failed : ".mysql_error()); 
     $message="Successfully Added"; 
     echo $message; 
     mysql_close($connect_mysql); 

     } 
     ?> 
+0

使用輸入類型'hidden'以及每行 – 2014-09-26 06:55:10

+0

你能發佈更多的代碼嗎?這是一個不完整的分割(以'?>'開始)你可能想要做的就是使用內聯if語句添加「checked」關鍵字,如:>(未經測試的代碼) – joshhendo 2014-09-26 06:55:11

+0

相同的名稱複選框與數組像小時[] – Khushboo 2014-09-26 06:55:18

回答

0

嘗試以下: -

<td><?php echo $rows['rno'];?></td> // values of rollno from database 
     <td><?php echo $rows['regno']; ?></td> // values of regno from database 
     <td><?php echo $rows['name'];?></td> 
     <td> 
     <input type="hidden" name="regno" value="<?php echo $rows['regno']; ?>"/> 
     <input type="checkbox" name="hour[]" value="1"/> 
     <input type="checkbox" name="hour[]" value="1"/> 
     <input type="checkbox" name="hour[]" value="1"/> 
     <input type="checkbox" name="hour[]" value="1"/> 
     <input type="checkbox" name="hour[]" value="1" /> 

價值,你會在後期得到(如果你已經使用了)

$_POST["regno"] for registeration number. 
的複選框值

$_POST["hour"]

+0

請告訴我如何從這個數組中獲得價值? – 2014-09-26 07:08:05

+0

謝謝你它成功地工作 – 2014-09-26 07:24:52

+0

我的榮幸.. :) – Khushboo 2014-09-26 07:25:45

相關問題