1

After a long search not able to find the solution

Undefined index: coursename in C:\wamp\www\StudentInformationProject\Student_new\courseinsert.php on line 17

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1'>

Here is the code

if(isset($_POST["button"]))
{
    $sql="INSERT INTO course(courseid, coursename, comment, coursekey)
    VALUES('".$_POST['courseid']."','".$_POST['coursename']."',
    '".$_POST['comment']."','".$_POST['coursekey']."')";

    if (!mysql_query($sql,$con))
    {
        die('Error: ' . mysql_error());
    }
    else
    {
        echo "1 record Inserted Successfully...";
    }
 }
Community
  • 1
  • 1

2 Answers2

1

One of your substituting variables has a double quote in it. Given the error message, it probably looks like:

foo "1" bar

You should escape such characters by doubling them, so it looks like:

foo ""1"" bar
Bohemian
  • 412,405
  • 93
  • 575
  • 722
0

It is possible that your value in comment contains a single quote, which would invalidate the SQL syntax...

Sparky
  • 14,967
  • 2
  • 31
  • 45