for ($key=0; $key < count($_POST['marks']); $key++) {
$from_marks = $_POST['from'][$key];
$get_marks = $_POST['marks'][$key];
//echo $from_marks." ";
if($get_marks > $from_marks){
// header("location: ../../pages/marks.php?over=err");
// break;
echo "Cant add more marks <br/>";
}
else{
echo $get_marks."<br/>";
$update_marks_query = $db->prepare(
"UPDATE sc_marks SET get_marks='"
.$get_marks
."' WHERE _sid='$sc_foreign_id' AND exam_type='$select_exam_type' ");
$update_marks_query -> execute();
}
}
The issue is occurred when I execute the code, I got the last fetched value in each rows of the table.
Data result after update:

WHEREclause of yourUPDATEstatement always matches every row in the table. I can't really give a more accurate answer without knowing where and how the used variables$sc_foreign_idand$select_exam_typeare defined, and what kind of data their associated fields contain in the database.forloop$query = $db->prepare("UPDATE sc_marks SET get_marks=? WHERE _sid=? AND exam_type=?");and then attach the parameters during each iteration with$query->execute($get_marks, $sc_foreign_id, $select_exam_type);. Your current approach is a security risk, apart from being less efficient than it could be. Read about SQL injection.