I have the following codes:
$query = "INSERT INTO main_table (id, matric_no, session, semester,
course_name, test, exam,practical)
VALUES (NULL, '$_POST[matric_no]', '$_SESSION[session]',
'$_SESSION[semester]', '$_SESSION[course_name]', '$_POST[test]',
'$_POST[exam]', '$_POST[practical]')";
mysql_query($query) or
die (mysql_error());
Then I tried:
echo "$_POST[semester]";
echo "$_POST[course_name]" ;
and they echoed out what I was expecting but not INSERTing INTO the database.. Only those two.
Thanks.
As pointed out in the comments, the problem was a column type mismatch that wasn’t visible in the original question.
However, it is a very bad idea to insert POST or other values directly – always run
mysql_real_escape_string()(or whatever sanitation function your database library provides) on them. More on SQL injections here.