This query works fine:
$query = "SELECT * from hired WHERE username = 'kaas' and dvd = 'dvd 2'";
But then I change it to this query:
$query = "SELECT * from hired WHERE username = " . $_SESSION['name'] . " AND dvd = " . $_POST['dvd'];
and it doesn’t work, even though the values should be the same as the top query. It goes straight to my error message, 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 ‘2’ at line 1
The dvd’s are having names like ‘dvd 1’ ‘dvd 2’ ‘dvd 3’. Why is it not working? Is there anything wrong in my query?
I tried to use the query with the data written down instead of using the session and post. It worked as I expected, and showed me an echo.
3
Answers
It needs to be
I forgot to put a ' around them, so it would see it (for example) as 'username = Fal' instead of 'username = 'Fal'
You have to concatenate variables inside query properly. Try this it will work.