0

I'm currently following a PHP tutorial, and I've got the following code::

$sql = "insert into practice (title, synopsis, genre, release, score, poster) 
        values('{$title}','{$synopsis}','{$genre}','{$release}','{$score}','{$poster}')";

if ($result = $mysqli->query($sql)) {
    // movie successfully added
    // redirect to index.php
    header("Location: index.html");
    exit;
}
elseif ($mysqli->connect_errno) {
    // there was a database error when inserting
    printf("Insert failed: %s\n", $mysqli->error);
}
else {
    printf("Sorry this isn't working! Insert failed: %s\n", $mysqli->error);
}

I'm currently getting the error that states "Sorry this isn't working..." the mysqli error simply states:

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 'release, score, poster) values ('fa','f','ff','ff','ff','ff')' at line 1.

I'm a complete newbie so I'm a bit lost in terms of what the syntax error might actually be. Thanks for any help in advance

TangoKilo
  • 1,785
  • 3
  • 25
  • 43

3 Answers3

8

release is a reserved keyword in MySql 5.1

You need to encapsulate with backticks

$sql = "insert into practice (title, synopsis, genre, `release`, score, poster)  
        values('{$title}','{$synopsis}','{$genre}','{$release}','{$score}','{$poster}')"; 
Steve
  • 213,761
  • 22
  • 232
  • 286
2

"release" seems to be a keyword of mysql.

Try to escape the key word with "`".

$sql = "insert into practice (title, synopsis, genre, `release`, score, poster) 
    values('{$title}','{$synopsis}','{$genre}','{$release}','{$score}','{$poster}')";
djleop
  • 687
  • 4
  • 18
2

It says the sytax problem starts right at "release". Since it doesn't look like a syntax error, it's probably a reserved word. See http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html.

bioneuralnet
  • 5,283
  • 1
  • 24
  • 30