Click here to Skip to main content
15,905,563 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Where is the error?
The machine said that:
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'='9'' at line 8

I know the session is the problem, but I do not know why. How do you change to be good?

The session[user][id] is working for a SELECT operation, but not the update.

What I have tried:

<pre lang="PHP">
                    $sql = "UPDATE `userzoli` SET 
                    WHERE 'id'='" . $_SESSION['user']['id'] . "'  ";
Updated 1-Aug-22 3:46am
Richard MacCutchan 1-Aug-22 9:08am    
The error message is telling you that $_SESSION['user']['id'] returns an empty string.
folza 1-Aug-22 9:14am    
It gets id not that is the problem. What could be the problem? Do you see a syntax problem?
Richard MacCutchan 1-Aug-22 9:37am    
Well you have changed the question now, so if the id is 9 then the WHERE clause will be:
WHERE 'id'='9'

I think you need a terminating semi-colon on your SQL statement, so it should be:
WHERE 'id'='" . $_SESSION['user']['id'] . "';";

1 solution

You're using apostrophes around a column name and MySQL doesn't support that. For column names you need to either use no quotations, or a backtick (`) symbol:
WHERE 'id'= <-- wrong

WHERE id=   <-- okay

WHERE `id`= <-- okay

But you also shouldn't be using string interpolation in your queries, you're opening yourself up to SQL injection attacks. Consider using PHP: mysqli_stmt::bind_param - Manual[^]
Share this answer
CHill60 1-Aug-22 10:49am    
Good spot! 5'd

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900