Mysql search and replace when involving "http://" - mysql

I'm trying to search and replace in MYSQL but get an error. I'm quessing it's because of the "http://"
Anyone got any suggestions when trying replace this type of thing?
Code entered:
update movies_news set select_page = replace(select_page, ‘http://movie’, ‘http://www.movie’);
But it throws the following 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 '://movie’, ‘http://www.movie’)' at line 1

Posting so it can be accepted:
update movies_news set select_page = replace(select_page, ‘http://movie’, ‘http://www.movie’);
contains smart quotes, which are not interpreted as normal single quotes, thus the syntax error. It should instead be
update movies_news set select_page = replace(select_page, 'http://movie', 'http://www.movie');
In general, be really careful about copying code to and from 'smart' text editors (Microsoft Word, etc)

Related

SQL ERROR - Error sql syntax

I am getting an error that I dont know how to deal with.
I am running the same code without issue for another column but for this column it refuses to work.
SELECT * FROM Players WHERE Character = 'momo' // This one wont work
SELECT * FROM Players WHERE Class = 'Fighter' // this one works
Character is a VARCHAR and Class is TEXT. I have tried changing Character to TEXT and I still get the same issue. The value 'momo' exists in the table.
ERROR: Couldn't connect to server. SQLSTATE[42000]: Syntax error or access violation: 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 '= ''' at line 1
Edit:
I am editing this incase someone find this and wants to know how it was fixed. User by the name of ueerdo Pointed out that I should use quotations and when I did, it worked. So I started looking into why it happened and I found out the SQL reserves Character for something else so it is something that I can't use unless it is in quotations.
It is best to delimit identifiers to prevent possible collision with reserved words and keywords.
SELECT * FROM `Players` WHERE `Character` = 'momo'

Simple SQL update query not working

I need to run this query but I get an error:
UPDATE wp_usermeta
SET meta_value = "a:1:{s:16:\"client_special\";b:1;}"
WHERE user_id = "1009";
But I get this 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 'UPDATE wp_usermeta
SET meta_value = "a:1:{s:16:\"cliente_especial\";b:1;}" W' at line 1
It is ok for me, I escaped the " with \ character.
As you discovered, and as my comment alluded, non-printing or hidden characters in your SQL statement can lead to unexpected syntax errors.
When confronted with what appears to be ludicrous messages, I find carefully retyping the statement into a different program helps decide whether it is a hidden character issue or a legitimate syntax issue.
It is the act of careful retyping that sanitizes the statement and rules out the non-printing characters. More than once I've done this and I imagine I will continue to do this for the rest of my career!

web application got a error mysql query

select b1.blog_id, blog_name, blog_desc, b1.blog_date, blog_author, blog_img, ifnull(count(blog_cmt),0) AS blog_cmt
from blog b1, user_blog b2"
I got a error in this:
Error Code: 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 '"' at line 1
Error #1064 means that MySQL can't understand your command. To fix it:
Read the error message. It tells you exactly where in your command
MySQL got confused.
Check the manual. By comparing against what MySQL
expected at that point, the problem is often obvious.
Check for reserved words. If the error occurred on an object identifier, check
that it isn't a reserved word (and, if it is, ensure that it's
properly quoted).
You need to remove the quotes at the end and run your query. Looks like there is a typo, you intended a ; instead.
select b1.blog_id, blog_name, blog_desc, b1.blog_date, blog_author, blog_img, ifnull(count(blog_cmt),0) AS blog_cmt
from blog b1, user_blog b2;

Error while updating inMySQL

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';

Syntax error 256 in WHERE clause

I am trying to update a field in my table and I keep getting this syntax error.
global $conn, $strTableName;
db_exec("UPDATE equipment SET EContractNum = " . $_SESSION[$strTableName."_masterkey1"] . " WHERE EContractNum = " . $values['EContractNum'], $conn);
Here is the error:
Error type: 256 Error Description: 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 econtractnum=35867111' at line
1
I have looked at several searchs that are similair to mine but I cannot figure out what I am doing wrong. I am fairly new at this so it is probably something simple. I just cant seem to make it work. Thanks for any help.
$_SESSION[$strTableName."_masterkey1"] is probably empty, or a string that needs to be quoted.
Also, don't put the raw values of variables into queries like that. Use a framework or prepared statements. It's good for security and it would also prevent this kind of error (well, it'd turn it into a different kind of error, at least).