I have some sample data like this which is generated from database sample data
I want to insert just single row value by Assign button in the corresponding row E.g. by clicking first-row assign button I want to insert 'CSE412', 'Artificial Intelligence', '3' My problem is when I click any of assign button all of the data which is generated from a database are inserted into the database. My try is
<?php
$stmt = $conn->prepare("SELECT * FROM tbl_course");
$stmt->execute();
$i = 0;
while($row = $stmt->fetch()) {
$student_id = $_GET['id'];
$course_id = $row['id'];
?>
<form class="" action="" method="post">
<tr style="border-top: 1px solid #32383e;">
<td><?php echo ++$i; ?></td>
<td><?php echo $row['course_code']; ?></td>
<td><?php echo $row['course_title']; ?></td>
<td><?php echo $row['credit']; ?></td>
<td>
<?php
if ($_SERVER["REQUEST_METHOD"]=="POST"){
$sql = "INSERT INTO tbl_course_enroll (student_id, course_id) VALUES ('$student_id', '$course_id')";
$conn->exec($sql);
}
?>
<input type="submit" name="" value="Assign" class="btn btn-primary">
</form>
</td>
</tr>
<?php
}
$conn = null;
?>