I am trying to replace "?t" string to "'t" (apostrophe t)
I enter this command in phpMyAdmin
UPDATE "myTable"
SET "myColumn" = REPLACE ("myColumn", "\?t", "\'t")
as suggested in How can I use mySQL replace() to replace strings in multiple records?)
I get this 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 #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 UPDATE "myTable"
SET "myColumn" = REPLACE ("myColumn", "\?t", "\'t") at line 1
What is wrong with my command?
Thanks
Don't quote table or column names. If you need to escape them use backticks
UPDATE `myTable`
SET `myColumn` = REPLACE (`myColumn`, '?t', '\'t')
Related
I am trying to run an SQL Query to replace the spaces in my filenames with an underscore:
UPDATE oc_product_image set image=replace(image,' ', '_');
I found this sql query here: Remove space and replace with _ in phpMyAdmin
I am running it in the SQL tab in phpMyAdmin
When I simulate it I get this 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 '' ''_') FROM oc_product_image WHERE' at line 1
What am I doing wrong?
Underscore is a special character in SQL. Try escaping it with a backslash and see if that helps.
I am working with MySQL and I am facing issues while updating the below command:
UPDATE group_access_mst SET
access='0',view='0',add='0',modify='0',delete='0',save='0',xl='0',import='0' WHERE role_id='1' AND page_id='1';
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 'add='0',modify='0',delete='0',save='0',xl='0',import='0' WHERE
role_id='1' AND p' at line 1
If I remove add,delete from the quesry it works fine!!
Is there any way i can make these command to work. I can understand that in MySQL ADD,DELETE,SELECT,INSERT are commands so it is not working.
In this case i need to change the fields names?
You should enclose the field names within back quote:
UPDATE group_access_mst
SET `access`='0',
`view`='0',
`add`='0',
`modify`='0',
`delete`='0',
`save`='0',
`xl`='0',
`import`='0'
WHERE role_id='1'
AND page_id='1';
Warning: 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 'color:red'>
and this my code :
$db->query("UPDATE members set id='{$this->test['id']}',
lvl='{$this->userlvl}', ip='{$this->test['IP']}',
time='{$this->test['time']}',
linechat='{$this->test['msg']}'
WHERE user='{$this->test['name']}'");
I'm a beginner so please tell me what is must be ^^
I have tried this
$fixchat = mysql_real_escape_string($this->test['msg']);
$fixname = mysql_real_escape_string($this->test['name']);
$db->query("UPDATE members set id='{$this->test['id']}',
lvl='{$this->userlvl}', ip='{$this->test['IP']}',
time='{$this->test['time']}', linechat='{$fixchat}'
WHERE user='{$fixname}'");
but I got this error :
Warning: 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 ''\wellington\'' at line 1...
One or more of the values in your $this->test array has double quote characters in it. Every dynamic element to a query string must be escaped by passing it through the appropriate escape function (in your case mysql_real_escape_string()). That will escape the quotes so the string is interpreted correctly.
Side note: You should be using the mysqli PHP library instead of mysql, which is deprecated. Also, a better alternative solution is to use parameterized queries.
solved by : addslashes function
$fixchat = addslashes($this->test['msg']);
$fixname = addslashes($this->test['name']);
$db->query("UPDATE members set id='{$this->test['id']}',
lvl='{$this->userlvl}', ip='{$this->test['IP']}',
time='{$this->test['time']}', linechat='{$fixchat}'
WHERE user='{$fixname}'");
Query to insert text in database is:
INSERT INTO uri VALUES('')
I'm getting follwing Syntax error:
MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
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 'liq" style="font-size:110%;font-family:'Alvi Nastaleeq', 'Nafees Nastaleeq', 'Na' at line 1
change this
title=\"Nasta'liq\"
^-----you have single quote alone here .get rid of it
to
title=\"Nasta liq\"
or
title=\"Nastaliq\"
I can't see what is wrong with this SQL:
UPDATE Show
SET EnterOnine = replace(EnterOnine, 'http://projects.example.co.uk', 'http://www.example.co.uk')
WHERE EnterOnine LIKE '%http://projects.example.co.uk%'
I am getting this error when I enter this into PHPmyadmin:
#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 'Show SET EnterOnine = replace(EnterOnine, 'http://projects.example.co.uk' at line 1
Show is a reserved word in mysql, escape with back ticks.
UPDATE `Show` SET ...