<thead>
<tr>
<th>User ID</th>
<th>User Name</th>
<th>Designation</th>
<th>M a r k A t t e n d a n c e</th>
</tr>
</thead>
<tbody>
<?php
$result = $conn->query("SELECT * FROM userdetails");
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
?>
<tr>
<td><?php echo $row['userid']; ?></td>
<td><?php echo $row['username']; ?></td>
<td><?php echo $row['designation']; ?></td>
<td>
<select name="brandlist[]" id = "brandlist" class=="col-sm-2">
<option value="present">Present</option>
<option value="absent">Absent</option>
<option value="late">Late</option>
<option value="absconding">Absconding</option>
<option value="resigned">Resigned</option>
<option value="terminated">Terminated</option>
</select>
</td>
</tr>
<?php
}
}else{
?>
<tr><td colspan="5">No Employees Found...</td></tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="col-12">
<button type="submit" name = "submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
This works all good, I can see rows displayed on screen and I can also select dropdown list and select attendance. Upon selecting submit, Below code runs all good and saves attendance in table.
<?php
if(isset($_POST['submit']));
{
$attendances = $_POST['brandlist'];
foreach($attendances as $item)
{
$query = "INSERT INTO attendance (attendancemarked) VALUES ('$item')";
$query_run = mysqli_query($conn, $query);
echo "<script language= 'JavaScript'>alert(' . $useriids . ');</script>";
}
}
?>
This entire code works all good. I am able to get data from userdetails table and display the records in row. I have added dropdown list in every row for marking attendance for employees. When I submit, attendance array saves all the attendance marked but userid, username, designation is not getting saved. I want these 3 fields also to get stored in the table attendance.
'
in field (such asdon't
or anything like that) would crash your query because SQL would think the'
was terminating the input string after then
.but userid, username, designation is not getting saved
....well those fields aren't mentioned in yourINSERT
statement, and you don't try to retrieve them from $_POST, and in fact they aren't even fields in your form...so why did you imagine that they would be saved? Go and put them as (hidden) fields in your form, then retrieve them from $_POST, then include them into your INSERT query. It's just the same as you already you do with the attendance data itself. That would seem to be the obvious solution. How/where/why are you stuck with that, exactly?name="brandlist[]"
for a list of attendance statuses?? This doesn't seem to make sense. As a tip, try to give your variables and fields meaningful names which reflect what they actually represent. It will make reading, understanding and debugging your code a lot easier (both for you, and for others).