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...";
    }
 }
3
  • 2
    "Undefined index: coursename" - you don't seem to be POSTing the course name. Also, I hope you learn about SQL injection soon! Commented Jun 25, 2013 at 20:26
  • Try echoing $sql and see if you can see what's wrong with it Commented Jun 25, 2013 at 20:29
  • As @Blorgbeard says, check this Commented Jun 25, 2013 at 20:29

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.