2

I got this error :

Database problem occur, please try again later.
- Error in query: INSERT INTO main SET title ='', url='www.jerseymurah.com', kod='jerseymurah', owner='Hasbul Aqill', tag='jersey, football, world cup', since='Feb 2010', desc='ssfsfsfsfs'
- 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 'desc='ssfsfsfsfs'' at line 1 (Error #1064)
- File: /home/yosh/domains/yosh.my/public_html/demo/admincp/tambah-save.php

and this is my mysql query code :

$query = "INSERT INTO main SET title ='".$ttile."', url='".$url."', 
kod='".$kod."', owner='".$owner."', tag='".$tag."', since='".$since."', 
desc='".$desc."'";
$db->rq($query);

Please help and thanks a lot!

4
  • 2
    If I am not wrong you are using UPDATE syntax to INSERT. Commented Dec 28, 2010 at 12:54
  • In the future, don't care about the PHP code if you get a SQL error: look at the SQL query first. PHP != SQL. Commented Dec 28, 2010 at 13:00
  • As an aside: Please, please, use parametrized statements, don't concatenate SQL fragments and parameters as strings, that is evil (-> SQL injection). See e.g. en.wikipedia.org/wiki/SQL_injection , and Best way to stop SQL Injection in PHP . Commented Mar 9, 2015 at 10:03
  • Also note that you are using a non-standard SQL syntax for your INSERT. It works with MySQL, so is not the cause of the error. Still, you might want to avoid DB-specific constructs unless there's no alternative. Commented Mar 9, 2015 at 10:05

3 Answers 3

7

DESC is a reserved word in mySQL.

You need to put that field in backticks:

`desc`="..."

maybe consider renaming the field.

mySQL reserved words in the manual

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

Comments

1

I think DESC is a reserved word, try escaping it with backticks.

Comments

-1
mysql_query("INSERT INTO main(title,url,kod,owner,tag,since,description) VALUES('$title','$url','$kod','$owner','$tag','$since','$desc')");

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.