S
S
Sergg892018-05-02 00:23:05
PHP
Sergg89, 2018-05-02 00:23:05

How to correctly insert variables into this query?

$query='SELECT*FROM answer WHERE title="'.$row['title'].'" ORDER BY id DESC LIMIT "'.$art.'", "'.$kol.'"';
Gives 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 '"0", "3"' at line 1

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel K, 2018-05-02
@PavelK

sprintf? And Limit must have numeric values, and you place a string there, i.e. remove the double quotes.

I
Immortal_pony, 2018-05-02
@Immortal_pony

The best option would be to use placeholders.
But in your case you can do this:

$query = "SELECT * FROM answer WHERE title='{$row['title']}' ORDER BY id DESC LIMIT {$art}, {$kol}";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question