i have a table and it display all the record in the table using $row. It generates multiple lines because it displayed all the value from the table. Then inside the table i created a form that comprised of only one single row. I want to record one value of that single $row using the studentnumber and subjectcode which is both from the $row in my query. Sorry for my confusing question and THANKS in advance.
code:
echo "<form name=\"grades\" action=\"insert.php\" method=\"post\" onsubmit=\"javascript:return confirm('Confirm Grade Submission?');\">";
echo "<td class=\"studentlist\">" . $row['studentnumber'] . "</td>";
echo "<td class=\"studentlist\">" . $row['subject'] . "</td>";
echo "<td class=\"studentlist\"><input type=\"text\" id= \"q1\" name=\"q1\" class=\"tbox\"></td>";
echo "<td class=\"studentlist\"><input type=\"text\" id= \"q2\" name=\"q2\" class=\"tbox\"></td>";
echo "<td class=\"studentlist\"><input type=\"text\" id= \"q3\" name=\"q3\" class=\"tbox\"></td>";
echo "<td class=\"studentlist\"><input type=\"submit\" value=\"Submit\"></td>";
echo "</form>";
insert.php
$studentnumber= $_POST['studentnumber'];
$subjectcode= $_POST['subjectcode'];
$query = ("SELECT * FROM grades WHERE studentnumber = '$studentnumber' && subjectcode = '$subjectcode'");
$result=mysql_query($query);
if($result)
{
if(mysql_num_rows($result) == 1)
{
$sql="INSERT INTO grades ( q1, q2, q3 )
VALUES('$_POST[q1]','$_POST[q2]','$_POST[q3]'')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<script type='text/javascript'>alert('Grade Successfully Submitted');location.href = '../administrator/admin_home.php';</script>";
}
}