bonaca bonaca - 3 months ago 8
PHP Question

mysql query wrong syntax

What is wrong with this syntax, please:

$stmt = $db->query('SELECT id, par, what, title, inde
FROM tmatria
ORDER BY inde ASC
where par = ' . $_SESSION["par"] . ';');


Error:


SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where par = 0' at line 1

Answer

The ORDER clause should come after WHERE clause

$stmt = $db->query("SELECT id, par, what, title,  inde FROM tmatria where par = '$_SESSION[par]' ORDER BY inde ASC");