MySQL INSERT ... WHERE syntax error - mysql

I can't find the reason for the error here, help please
$query = "INSERT INTO users ( name, city, country, phone, twitter, bio, gender ) VALUES ('".$name."', '".$city."', '".$country."', '".$phone."', '".$twitter."', '".$bio."', '".$gender."') WHERE username = '".$username."'";
The error is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE username = ''" at line 1

Where clauses are not part of the Insert statements. You cannot INSERT...WHERE

If you want to specify a WHERE clause, you probably want an UPDATE statement instead:
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;

Related

Error in sql syntax value ? but it's showing the value?

the title isn't very specific but I don't know how to make it better. I've got this error in my sql telling me something is wrong but I don't understand why it's wrong, currently using mysql 8.0.24. If you wonder why it looks strange it's because I use it in lua
Sql:
local q = [[SELECT id, hex_id, steam_id, community_id, name, ip, rank FROM users WHERE hex_id = #id;]]
local v = {["id"] = hexId}
Error:
An error happens for query "SELECT id, hex_id, steam_id, community_id, name, ip, rank FROM users WHERE hex_id = ?; : ["steam:*****"]": ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM users WHERE hex_id = 'steam:*****'' at line 1
RANK is a keyword in MySQL 8. You need to enclose it inside backticks:
SELECT id, hex_id, steam_id, community_id, name, ip, `rank` FROM users ...

MySQL syntax error when using sqlite3 query

I just wanted to switch from sqlite3 to using MySQL but I get errors in this query:
SELECT
metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
pro.latitude,
pro.longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM (metapp_notif
join (metapp_profil
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id) AS pro
ON metapp_notif.send_id = pro.user_id)
WHERE metapp_notif.rec_id =% d;
I'm getting this error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'pro on metapp_notif.send_id=pro.user_id) where
metapp_notif.rec_id=2' at line 1
I was searching for differences between sqlite3 and mysql but can't figure out what is wrong.
Thanks in advance!
Try this syntax in Mysql
SELECT metapp_notif.id,
name,
age,
place,
note,
metapp_notif.lat,
metapp_notif.longt,
haslatlong,
dati,
ntype,
grpm_id,
image,
send_id,
latitude,
longtitude,
metapp_notif.dati,
metapp_notif.activity
FROM metapp_profil
join metapp_notif
ON metapp_notif.send_id = metapp_profil.user_id
join metapp_userlocation
ON metapp_profil.user_id = metapp_userlocation.user_id
WHERE metapp_notif.rec_id like '% d'; -- Not sure what you are trying to do here

what is wrong following mysql query?

INSERT INTO lm_empleavetypemodelmap(leavetypeid,userid)
VALUES(1682,"b0c6c81f-a20a-4daa-9038-831478d8e11b")
WHERE lm_empleavetypemodelmap.userid NOT IN
(SELECT lm_empleavetypemodelmap.userid
FROM lm_empleavetypemodelmap
WHERE lm_empleavetypemodelmap.leavetypeid = 1683)
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE lm_empleavetypemodelmap.userid NOT IN( select lm_empleavetypemodelmap.user' at line 1
You do not use where with values. Perhaps the stuff at the end is just accidental garbage and you just want:
INSERT INTO lm_empleavetypemodelmap(leavetypeid, userid)
SELECT 1682, 'b0c6c81f-a20a-4daa-9038-831478d8e11b';
Or, in what looks rather strange to me:
INSERT INTO lm_empleavetypemodelmap(leavetypeid, userid)
SELECT 1682, 'b0c6c81f-a20a-4daa-9038-831478d8e11b'
WHERE NOT EXISTS (SELECT 1 FROM lm_empleavetypemodelmap WHERE leavetypeid = 1683)
That is, insert 1682, if 1683 doesn't exist. Usually you care about the value being inserted, not the next value.

My sql syntax error 1064 -can't find what is wrong

I go this error message when I run this query
SELECT name,state FROM customers WHERE state ‌IN ('CA','NC','NY')
Error
SQL query: Documentation
SELECT name, state
FROM customers
WHERE state ‌IN(
'CA', 'NC', 'NY'
)
LIMIT 0 , 30
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '‌in ('CA','NC','NY') LIMIT 0, 30' at line 1
I has a look there http://dev.mysql.com/doc/refman/5.6/en/error-messages-server.html but I still can't find the reason why
Thank you
Remove the = after IN
SELECT name, state FROM customers
WHERE state ‌IN ('CA','NC','NY')
SELECT name,state FROM customers WHERE state ‌IN ('CA','NC','NY')
You can not use the '=' with an IN
I tried to copy your query and run it in MySQL
You have some strange "hidden" character before IN
If you delete it, then everything works fine

SQL syntax error adding data opencart DB

Im looking to add all products that dont have attribute_id = 12 into oc_product_attribute,
But getting a syntax error...
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '12) select ocp.product_id from oc_product ocp where ocp.product_id not in (SE' at line 1
insert into `oc_product_attribute` (ocp.product_id, 12)
select ocp.product_id from oc_product ocp where ocp.product_id not in (SELECT oca.`product_id`
FROM `oc_product_attribute` oca where oca.attribute_id = 12)
Am I missing something here, quite new to SQL.
Usually you have to enumerate columns in insert statements.
insert into `oc_product_attribute` (ocp.product_id, 12)
must be
insert into `oc_product_attribute` (ocp.product_id, some_column_name)
and I guess it may be attribute_id.
For more details, please see the reference manual -> http://dev.mysql.com/doc/refman/5.6/en/insert-select.html