Actually i want to store values fetched from one database(student info) into other database(attendance) along with selected status of their attendance, i want to store data in every iteration of while loop. The data retrieved from student info database is being successfully stored into attendance database but it does't stores the particular selected option in each iteration, it only stores the value of latest option selected and overwrites previous status of selected option.
<html>
<head>
</head>
<body>
<?php
error_reporting(E_ALL ^ E_DEPRECATED);
include("config.php");?>
<div class="form-container">
<form method="post" action="" role="form">
<!-- <div class="container"> -->
<div class="col-lg-3">
<div class="form-group">
<?php
$qs=mysql_query("select * from student_table");
?>
<table border=1>
<?php
while($stid=mysql_fetch_row($qs))
{
?>
<tr>
<td ><?php echo $stid[0]?></td>
<td><?php echo $stid[1]?></td>
<td>
<select name="present" >
<option value=""> ---Select Attendence--- </option>
<option value="P"> Present </option>
<option value="A"> Absent </option>
</select></td>
</tr>
<?php
$stud= $stid[0]; //roll no of student from student database
$subj= $stid[1]; //name of student from student database
$date = date('Y-m-d H:i:s'); //date
if(isset($_POST['present'])){ //selected option value, but it gets overwritten and at the end displays latest value except particaular value of every iteration
$department=$_POST['present'];
$query=mysql_query("Insert into tbl_attendence (StudentRollNumber,SubjectId,Attendence,Date)VALUES('$stud','$subj','$department','$date')");
if(!$query)
{
echo mysql_error();
}
}
}
?>
</table>
</div>
</div>
<button type="submit" name="save" value="Save" class="btn btn-success btn-sm">Save</button>
</form>
</body>
</html>