I'm getting an error about my query, and i'm not understanding what the problem might be. The error i get 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 'range = '55', atkspeed = '0.95', m_damage = '0', p_damage = '38', mprotection = ' at line 1
While the code i'm using is this one
$id = mysql_real_escape_string($_POST["id"]);
$value0 = mysql_real_escape_string($_POST["value0"]);
$value1 = mysql_real_escape_string($_POST["value1"]);
$value2 = mysql_real_escape_string($_POST["value2"]);
$value3 = mysql_real_escape_string($_POST["value3"]);
$value4 = mysql_real_escape_string($_POST["value4"]);
$value5 = mysql_real_escape_string($_POST["value5"]);
$value6 = mysql_real_escape_string($_POST["value6"]);
$value7 = mysql_real_escape_string($_POST["value7"]);
$value8 = mysql_real_escape_string($_POST["value8"]);
$value9 = mysql_real_escape_string($_POST["value9"]);
$value10 = mysql_real_escape_string($_POST["value10"]);
$query="UPDATE char_stats SET vita = '$value0', mana = '$value1', speed = '$value2', range = '$value3', atkspeed = '$value4', m_damage = '$value5', p_damage = '$value6', mprotection = '$value7', pprotection = '$value8', hp5 = '$value9', mp5 = '$value10' WHERE id_char_stats='$id'";
I'm using also other very similar queries so i don't get what the problem might be. I was thinking about the underscore on char_stats so i tried using
char\_stats
for escape, but it's not working anyway.
Thanks in advance
create table t11
(
id int not null,
`range` int not null,
speed int not null
);
update t11 set range='11', speed=1; -- blows up
update t11 set `range`='11', speed=1; -- fine
update t11 set `range`=11, speed=1; -- fine
Moral of the store: back-tick range. Even the create table blows up without it.
see mysql keywords and reserved words here. Range is one of them.
So your query would become:
$query="UPDATE char_stats SET vita = '$value0', mana = '$value1', speed = '$value2', `range` = '$value3', atkspeed = '$value4', m_damage = '$value5', p_damage = '$value6', mprotection = '$value7', pprotection = '$value8', hp5 = '$value9', mp5 = '$value10' WHERE id_char_stats='$id'";
Related
I'm using MySqlCommand for perform query insert in my vb.net application, now I've this query:
UPDATE primo_appointments SET
book_datetime = #parameter1,
start_datetime = #parameter2,
end_datetime = #parameter3,
notes = #parameter4,
hash = #parameter5,
is_unavailable = #parameter6
WHERE hash = xqA5jdsFBLPTrvy5kKHfgXBZdv9Hs2Ld
AND lastUpdated = 12-01-2016 15:53:47.3978486
when I do: .ExecuteNonQuery() this error appear:
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 '15:53:47.3978486' at line 1.
What is wrong?
Your lastUpdated and hash is not enclosed in single quotes which is the cause of your error.
The fix for this is not to enclose it in quotes, but to use a parameter for these values as well as the others:
UPDATE primo_appointments SET
book_datetime = #parameter1,
start_datetime = #parameter2,
end_datetime = #parameter3,
notes = #parameter4,
hash = #parameter5,
is_unavailable = #parameter6
WHERE hash = #oldHashString
AND lastUpdated = #lastUpdatedDate
When you use a parameterised list, you don't have to remember whether a field needs to be surrounded by quotes or not - this is handled for you. It also protects you from SQL injection attacks.
your varchar should between 2 ', you query should be:
UPDATE primo_appointments SET book_datetime = #parameter1,
start_datetime = #parameter2, end_datetime = #parameter3,
notes = #parameter4, hash = #parameter5, is_unavailable = #parameter6
WHERE hash = 'xqA5jdsFBLPTrvy5kKHfgXBZdv9Hs2Ld'
AND lastUpdated = '12-01-2016 15:53:47.3978486'
I’m trying to update a table that is joined with another one to update the right record.
Here is my command so far:
UPDATE
links l
SET
l.l_id = `[value-1]`,
l.l_facebook = `[value-2]`,
l.l_youtube = `[value-3]`,
l.l_twitter = `[value-4]`,
l.l_googleplus = `[value-5]`,
l.l_rss = `[value-6]`,
l.l_homepage = `[value-7]`,
l.l_freigegeben = `[value-8]`
JOIN
sponsering ON l.l_id = sponsering.links_l_id
WHERE
sponsering.s_userID = 2
Trying to run the command in phpmyadmin gives me the following error message:
1064 - 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 'JOIN sponsering ON l.l_id = sponsering.links_l_id WHERE
sponsering.s_user' at line 12
I need to join the table sponsering because this gives me the correct record in the links table.
How can I solve this?
Try this
UPDATE
links l,
sponsering s
SET
l.l_faceook = `[value-2]`,
l.l_youtube = `[value-3]`,
l.l_twitter = `[value-4]`,
l.l_googleplus = `[value-5]`,
l.l_rss = `[value-6]`,
l.l_homepage = `[value-7]`,
l.l_freigegeben = `[value-8]`
WHERE
l.l_id = s.links_l_id AND
sponsering.s_userID = 2
In MySQL, the join is part of the update statement itself. There is no separate from:
UPDATE links l JOIN
sponsering s
ON l.l_id = s.links_l_id
SET
l.l_id = `[value-1]`,
l.l_faceook = `[value-2]`,
l.l_youtube = `[value-3]`,
l.l_twitter = `[value-4]`,
l.l_googleplus = `[value-5]`,
l.l_rss = `[value-6]`,
l.l_homepage = `[value-7]`,
l.l_freigegeben = `[value-8]`
WHERE s.s_userID = 2;
Some other databases use a FROM clause for the same purpose.
I added a column into table A and right now it is empty. What i want to do is take the phone column from table consumer and input it into appphone of table diabetic as long as the first name, last name, address, city, state, and zip, match up in both tables. Below is the query i have been trying and in theory should work but is not. I keep getting the same error no matter which way i change the query.--
error 'subquery returns more than one row'
UPDATE Diabetic_DB
SET Diabetic_DB.AppPhone = (SELECT Consumer.PHONE FROM Consumer
WHERE Consumer.FN = Diabetic_DB.FirstName
and Consumer.LN = Diabetic_DB.LastName and Consumer.ADDR = Diabetic_DB.Address1
and Consumer.CITY = Diabetic_DB.City and Consumer.ST = Diabetic_DB.State
and Consumer.ZIP = Diabetic_DB.Zip)
WHERE EXISTS (SELECT DISTINCT(PHONE) FROM Consumer WHERE Consumer.FN = Diabetic_DB.FirstName
and Consumer.LN = Diabetic_DB.LastName and Consumer.ADDR = Diabetic_DB.Address1
and Consumer.CITY = Diabetic_DB.City and Consumer.ST = Diabetic_DB.State
and Consumer.ZIP = Diabetic_DB.Zip)
the original query i ran looked like this.
UPDATE Diabetic_DB
SET Diabetic_DB.AppPhone = Consumer.PHONE
WHERE EXISTS (SELECT * FROM Consumer WHERE Consumer.FN = Diabetic_DB.FirstName
and Consumer.LN = Diabetic_DB.LastName and Consumer.ADDR = Diabetic_DB.Address1
and Consumer.CITY = Diabetic_DB.City and Consumer.ST = Diabetic_DB.State
and Consumer.ZIP = Diabetic_DB.Zip)
Try something like this:
UPDATE Diabetic_DB
INNER JOIN Consumer ON
Consumer.FN = Diabetic_DB.FirstName
and Consumer.LN = Diabetic_DB.LastName and Consumer.ADDR = Diabetic_DB.Address1
and Consumer.CITY = Diabetic_DB.City and Consumer.ST = Diabetic_DB.State
and Consumer.ZIP = Diabetic_DB.Zip
SET Diabetic_DB.AppPhone = Consumer.PHONE
I try to change my code from MYSQL to SQL and i got an error (SQL Syntax 'Limit').
So i tried to change my query and update with "TOP" but seems to work only with SELECT.
So, how can i change this MYSQL query :
$fct="UPDATE `users` SET `STREAM_TITRE` = '$STREAM_TITRE',`STREAM_URL` = '$STREAM_URL',`STREAM_DESC` = '$STREAM_DESC',`STREAM_GENRE` = '$STREAM_GENRE' WHERE `ID` =$IDSESS LIMIT 1";
Here is my SQL Code without Limit :
$fct="UPDATE users SET STREAM_TITRE = '$STREAM_TITRE', STREAM_URL = '$STREAM_URL', STREAM_DESC = '$STREAM_DESC', STREAM_GENRE = '$STREAM_GENRE' WHERE ID = '$IDSESS'";
Thanks
It's not very clear which version of your query is working and which is not - and in what DBMS.
If ID is of char or varchar type, you are missing some quotes in the LIMIT version. Although MySQL is not very picky and you won't have many issues, with or without quotes:
$fct = "
UPDATE users
SET STREAM_TITRE = '$STREAM_TITRE'
, STREAM_URL = '$STREAM_URL'
, STREAM_DESC = '$STREAM_DESC'
, STREAM_GENRE = '$STREAM_GENRE'
WHERE ID = $IDSESS --<-- this should be '$IDSESS' , right?
----- or $IDSESS , depending on the datatype
LIMIT 1
";
Note: The LIMIT n works in MySQL and PostgreSQL, but not in some other DBMS. Plus, I don't think you really need it anyway, as the ID is probably the Primary Key of the table.
If you are trying to convert the statement from MySQL to SQL-Server, you should not use the backquotes and replace LIMIT 1 with TOP (1):
$fct = "
UPDATE TOP (1) users
SET STREAM_TITRE = '$STREAM_TITRE'
, STREAM_URL = '$STREAM_URL'
, STREAM_DESC = '$STREAM_DESC'
, STREAM_GENRE = '$STREAM_GENRE'
WHERE ID = $IDSESS
";
I am generating the sql statement below based on some coldfusion logic, but it is erroring and I can't seem to find the cause, I have tried making many different modifications to it and nothing seems to be helping.
UPDATE MAIN_RECORDS
SET JONUM = NULL,
SET CUSTNAME = 'Super Sweet Name',
SET CONTACTDT = 02/28/2011,
SET ENGRECDT = 03/07/2011,
SET HOW_WR_DT = 03/07/2011,
SET COMM_DT = 03/29/2011,
SET FACAVALDT = NULL,
SET FAX_SUPDT = 03/07/2011,
SET LINENUM = 'CLPRO L6',
SET POLENUM = 'CLPRO 125 T T3',
SET REASON = '03/07/11 NO VAC FAC THIS IS THE WRONG INFORMATION IT WAS ON HERE TWICE',
SET REC_TYPE = 'H',
SET ORDER_TYPE = 'P',
SET CANCEL_ORDER = 'Y',
SET State_abbr = 'IL',
SET dbfk_state = 17,
SET xx_streetnumber = '2626',
SET xx_street = 'Fake St',
SET xx_city = 'NEWTON',
SET xx_class_of_service_ind = 'R',
SET xx_cellphone_ind = '1',
SET xx_assigned_phone = '3045653897',
SET xx_exchange_name = 'NEWTON',
SET XX_new_ref_code = '60',
SET xx_new_service_type = '11',
SET ORD_COMDT = 03/11/2011,
SET delivery_date = NULL
WHERE ordernum = '08824112' AND exchnum = '304565'
Currently the error that management studio is giving me is:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'SET'.
You only need 1 SET statement, instead of the multiple ones you have.
Also, your dates need to have single quotes around them.
e.g.:
UPDATE MAIN_RECORDS
SET JONUM = NULL,
CUSTNAME = 'Super Sweet Name',
CONTACTDT = '02/28/2011',
ENGRECDT = '03/07/2011',
HOW_WR_DT = '03/07/2011', .....
Look at the UPDATE statement. The syntax in the post is all wrong :)
The relevant portion:
SET
{ column_name = { expression | DEFAULT | NULL }
| #variable = expression
| #variable = column = expression } [ ,...n ]
Note that SET can only be specified once. The ,...n signifies the previous consuct (that in the {}) can be specified an additional n times, separated with a comma: the SET keyword itself, however, is outside that construct.
Happy coding.
Well generally the command syntax for this would follow this logic
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
so only one SET not the multiple that you have
Only one SET is needed in update Keyword to update n number of columns - example:
Update Employee
set City = Chennai,Country ='India',Employee name = 'Vignesh'
where Employee Id = 1X234