0

trying to add data to mySQL db.

I get this 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 'MATCH(time, date, location, weather, team_id) VALUES('t', 't', 't','t','2')'

this is the PHP code snippet:

$sql = "insert into MATCH(time, date, location, weather, team_id) VALUES('$time', '$date', '$location','$weather','$team_id')";

I cant see any syntax errors

1

2 Answers 2

3

MATCH is a reserved for a function used in fulltext search:

http://dev.mysql.com/doc/refman/5.5/en/fulltext-search.html

That's not a php syntax error. It's a Mysql syntax error. I suggest changing the table's name.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks, what is the correct syntax for naming tables i.e. rugby_Match, rugby_match etc...
There is an alternative to just changing the table's name. Maybe the OP likes the name. ;-) - Offering the same "deal" here too.
2

Try

$sql = "INSERT INTO `MATCH` (`time`, `date`, `location`, `weather`, `team_id`) VALUES ('".$time."', '".$date."', '".$location."','".$weather."','".$team_id."')";

Using the backtick character ` you can distinguish names you gave to your table or columns from reserved words of the MySQL language. Leaving them out might seem more compfortable at first, but can be a pain later.

E.g. one should know that mysql syntax is not case sensitive. So even if you write match you will get this problem. A list of the reserved words can be found at the link Mark gave you in his comment.

You might also want to read up on MySQL Syntax in general:

4 Comments

If you add the reason why and a fair explanation, I might even +1 this. Saying just Try isn't enough, not in my books anyway ;-)
Oh come now, you can do better than that. Read Mark Baker's comment, and learn ;-)
Sorry, but I didn't want to copy Marks answer. He was faster, but when I saw his comment I already pushed backtick so often that I wanted to give him the code anyway ^^
No problemo (no permanent damage done) - It was just a comment (notice the word if in his comment). Sometimes people don't want to bother putting in answers for questions as such. Plus, they tend to open up a potential "Can of Worms". Will upvote this, but in the future, do try to make answers as informative as possible. It's beneficial for all, plus you stand at getting more upvotes. ;-)

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.