Sep Sep - 24 days ago 11
SQL Question

SQL syntax error MariaDB server version for the right syntax to use near 'WHERE ID = 4' at line 1

I have this line of

SQL
:

$sql = "SELECT ID, ListStID, ListEmail, Title FROM $entry_database
WHERE ID = '". $ReqBookID ."'";
$result = mysqli_query($conn, $sql);


As you can see, I am selecting an entry's ID, ListStID, ListEmail and Title Column if ID is equal to a string of numbers (or text), which is given by user in a form.

Everything is ok, and I don't get any syntax error when I write the code (I am using a code editor software. However, when I use it online, I get this error:


Error: SELECT ID, ListStID, ListEmail, Title FROM WHERE ID = '4' 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 ID
= '4'' at line 1


I am very new to PHP, and I'm sure I am either adding extra ' or ", so I would really appreciate it if you could help me with this issue. I have tried the answers for similar questions, but no success yet.

UPDATE 1:

So thanks to all those who pointed it out, I fixed the $entry_database error, and and it's working properly now.

Many MANY Thanks for all the efforts you made.

Answer

You have empty $entry_database variable. As you see in error: ListEmail, Title FROM WHERE ID bewteen FROM and WHERE should be name of table. Proper syntax of SELECT:

SELECT columns FROM table [optional things as WHERE/ORDER/GROUP/JOIN etc]

which in your way should become:

SELECT ID, ListStID, ListEmail, Title FROM some_table_you_got WHERE ID = '4'