i want to record a user inputed value and at the same time copy a single data from another table. is it possible?
here is my code:
$sql="INSERT INTO grades (studentnumber,subjectcode)
VALUES
('$_POST[studentnumber]','$_POST[subjectcode]')";
$sql="INSERT INTO grades (course) SELECT course FROM students WHERE studentnumber= '$_POST[studentnumber]'";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<script type='text/javascript'>alert('Record Successfully Added'); location.href = '../instructor/cvsu-sis_students.php';</script>";
thanks in advance and sorry for my elementary question.
You can do it in one query if that’s what you are asking about, also remember to escape the strings to avoid SQL Injection: