0

How can I fix this line in PHP/MySQL? The server returns the 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 ''id', 'title', 'yes', 'no') VALUES (2,test, 0, 0)' at line 1

for the line

mysql_query("INSERT INTO things('id', 'title', 'yes', 'no') VALUES ($counter,$thing, 0, 0);", $con);

2 Answers 2

2
"INSERT INTO things (`id`, `title`, `yes`, `no`) VALUES ($counter,$thing, 0, 0);"

Use ticks and not single quotes. Also, you are not quoting your string there. You should do proper sanitization.

You should switch to PDO or mysqli. mysql_ functions are deprecated.

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

2 Comments

Thanks, that seems to fix that problem. But now it's saying Unknown column 'testtest' in 'field list' where testtest is $thing.
right because you don't quote your string. ($counter,'$thing', 0, 0) would technically work but you really should do proper sanitizing through built in mysqli or PDO functions. Any tutorial on the two will show you how to do that
0

You need quotes around $counter and $thing

mysql_query("INSERT INTO things('id', 'title', 'yes', 'no') 
VALUES ('$counter','$thing', 0, 0);", $con);

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.