Sql syntax error using UPDATE database query

1.2k Views Asked by At

evening all, i have an issue with a syntax sql error

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 username = danny (name, url, banner, description, sponsor, date, password)' at line 1

Here is my code

$query = "UPDATE websites where username = $login_session (name, url, banner, description, sponsor, date, password) VALUES ('$n', '$b', '$d', '0', now(), SHA('$p'))";
2

There are 2 best solutions below

8
On BEST ANSWER

That's because your UPDATE statement syntax is wrong. Check MySQL documentation for proper UPDATE syntax. I think you meant to do a INSERT rather

INSERT INTO websites (name, url, banner, description, sponsor, date, password) 
VALUES ('$login_session', '$n', '$b', '$d', '0', now(), SHA('$p'))

EDIT:

I think this is what you are after

UPDATE websites SET name = '$n', 
url = '$b', 
banner = '$d', 
description = '0', 
sponsor = 'some_value_here', 
date = now(), 
password = SHA('$p')
where username = '$login_session';
0
On

Your MySQL query is wrong, as the error says, check the manual.

In UPDATE you don't use table(field,field1) values('value','value1') like in INSERT, you use field='value', field1='value1' also, WHERE should be at the end, the right order is query + where + order + limit. MySQL is not that flexible.