名前が何を表しているのかわからない (生徒または教師)。3 つの科目があり、各教師がそれぞれのスコアを提出する必要があり、すべてのデータを (roll_num, name,科目 1 のスコア、科目 2 のスコア、科目 3 のスコア)。それが本当なら、これはあなたのために働くはずです:
if (isset("name") && isset("roll_number)){
$name = $_GET["name"];
$roll_no = $_GET["roll_number"];
if (isset("subject1_score")){
$subject = "subject1_score";
$score = $_GET['subject1_score'];
}elseif(isset("subject2_score")){
$subject = "subject2_score";
$score = $_GET['subject2_score'];
}elseif(isset("subject3_score")){
$subject = "subject3_score";
$score = $_GET['subject3_score'];
}else{
$subject = "";
$score = "";
}
$con = mysql_connect("host","username","password");
if (!$con) die('Could not connect: ' . mysql_error());
mysql_select_db($con, dbname);
$query1 = "SELECT * FROM result WHERE roll_number='$roll_no'";
$result1 = mysql_query($query1) or die(mysql_error());
$num = mysql_num_rows($result);
if($num == 0 && $subject != ""){
$query2 = "INSERT INTO result(roll_number, name, $subject) VALUES('$roll_no', '$name', '$score')";
mysql_query($query2) or die(mysql_error());
}elseif($num > 0 && $subject != ""){
$query2 = "UPDATE result SET $subject='$score' WHERE roll_number='$roll_no'"
}else{
echo "subject score is empty";
}
mysql_close($con);