SQL ERROR - Error sql syntax - mysql

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'

Related

Getting SQL error for replace function

I'm not to sure why this is happening and i've been trying to figure it out now for a while.
I've got the follow code
SELECT (MAX(replace(replace(replace(`sku`,'PA1-',''),'TES-',''),'BOX-',''))+1) AS maxValue FROM `product` WHERE `sku` LIKE '%PA1-TES-BOX%'
This was working a while back and nothing has changed code wise, I can only assume that a server changes has caused this to return 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 'maxValue FROM ``product`` WHERE ``sku`` LIKE '%PA1-TES-BOX%'
Basically this SQL was built to find the first 3 section of this SKU code and return the ending + 1 so 002 would then return 003 to ensure unique sku codes.
Maybe the replace function has changed, i'm not entirely sure.
Does anyone have any ideas why this suddenly is throwing the error above?
I don't see an obvious syntax error. But assuming the number is the last hyphenated item in the sku, the code could more easily be written as:
select (substring_index(sku, '-', -1) + 1) as maxvalue
. . .
One possibility for the syntax error is that an unprintable character crept in around the as.

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;

Syntacts error in mysql query

Someone gave me this query to delete community from a database on my server using phpMyAdmin, it worked when he use it so I asked him to send it to me, but I get a error
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 '"SELECT * FROM `connections` WHERE 1" :
delete from connections where communit' at line 1
I did a search on the error but could not figure it out.
"SELECT * FROM `connections` WHERE 1" :
delete from connections where community="XYZ"
You should separate your queries with ; and not :
The error you are receiving as you've shown it is because this line is incorrect:
SELECT * FROM `connections` WHERE 1"
First because it's ending in an unnecessary double quotation mark. MySQL does not use double quotes but single quotes, and even still the other single quote is not there to match it.
The single quotes are also a problem for community="XYZ", this should read: community = 'XYZ'
Secondly, you don't have a condition for your where statement, you must be missing something like:
WHERE columnName = 1;
If you were trying to select everything from connections, you can just remove that where clause all together.
EDIT
In addition, MySQL queries are separated by a semi-colon, not a colon, so MySQL will not realize you are trying two different queries.

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

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)

MySQL query sanity check, for update query

I have this query
update user_remember_me set
when='2012-07-06 05:44:27',
hash='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7'
where user = '21';
and I am getting this error
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 'when='2012-07-06 05:44:27', hash='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7' wher' at line 1
Im failing to miss the connection here, I've used simple updates like this everywhere without issue til this, maybe Im getting to tired, but this is gonna drive me nuts til I have an answer
When is a key word in mysql, change the column name
or you can use it as
`when`='2012-07-06 05:44:27'
when is a reserved word in mysql
update user_remember_me set
`when`='2012-07-06 05:44:27',
`hash`='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7'
where user = '21';
So you must backtick your column
when is a keyword within MySQL. You have to escape it, if you want to use it as a column identifier (as you should with all column identifiers!):
UPDATE user_remember_me
SET
`when`='2012-07-06 05:44:27',
`hash`='c8e9d2c0dd156b5c68d0b048e5daa948e6b8fac7'
WHERE `user` = '21';