I'm sure this is something to do with how I've set the server up. Total server noob.
When I enter the query
SELECT * FROM `models` WHERE `sex` = 'x'
I get an error saying
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 '' x ' '
SELECT * FROM `models` WHERE `sex` = ' x '
I have removed the ; from the code examples for clarity.
Is this a php.ini setting I need to change? Is this an input conversion?
Thanks in advance.
Don't use "html entities" when writing SQL.
' is one way of encoding an apostrophe ' for display on web pages. I don't know how you go that into your code, but that seems to be the problem.
Only use the PHP function htmlentities() for writing to the web page.
What editor are you using?
Edit:
Check php.ini. You may need magic_quotes_gpc = Off
Related
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'
I am trying to find a weird character thats in front of my £ sign and replace it with nothing.
Coding I tried was
update [orders_total]
set [text]=replace([text],'[Â]','[]');
but mysql returns this
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 '[orders_total] set [text]=replace([text],'[Â]','[]')' at line 1
I know nothing of Mysql but its going to take me ages to manually remove these chars so any help would be much appreciated.
Thanks in advance
Thats not mysql syntax and in mysql it should be as
update orders_total
set text=replace(text,'Â','');
Abhik is absolutely right in his answer. An alternate form of writing MySQL queries is:
update `orders_total` set `text` = replace(`text`, '..', '...');
Backticks are not required. They may be valuable when a table's column is named order, for example. Order is a reserved keyword used in order by ... clause. In order to use a reserved keyword like order, use backticks.
Example:
select `order`, `id`, ... from `tablename` where .... order by `order`;
I use SQuirreL SQL client Version 3.5.3
I wanted to do an insert of a text with accent like éèà but I get a syntax error. The follow select statement doesn't work:
select 'élève';
The error is the following:
Error: Syntax error or access violation, message from server: "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 ''élèv' at line 1"
when I delete the é and è it works.
Does someone know how I can solve that accent problem ?
I just tried in my version of squirrel:
select 'élève' from dual;
Its on oracle. It worked without error. You probably need to make sure your connection is set up to handle unicode and that the underlying database supports that character set. Is that syntax even valid for your database? (I had to add "from dual" in order for it to become valid SQL).
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)
##SESSION.sql_mode;
##GLOBAL.sql_mode;
both come up blank, the my.cnf shows no "NO_BACKSLASH_ESCAPE" flag and this is a section of a query which runs on my local server but not on my main.
UPDATE `table`
SET `data` = "[{\"_talent\'s\"etc"
Now I know I can use "[{""_talents""etc" but I'd rather not since it is much easier for me to keep to my current escaping security methods which have always worked before.
The charset is UTF-8 of the table I'm updating. The strangest thing is that it works on insert but not update!
This one really has me scratching. Any ideas?
Cheers
edit:
I've found out that the server is trying to interpret the query like so:
Failed to execute SQL : SQL UPDATE `build` SET `data` = "[{\"_talent\'s" WHERE `build_id` = 1 AND `userId` = 1128; failed : 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 `build` SET `data` = "[{\\"_talent\\'s" WHERE `build_id` = 1 AND `userId`' at line 1
Yet surely it should be the same, why is the SQL engine escaping my escapes!? (if I leave out the escapes the query still fails)
You can try this -
UPDATE 'table'
SET 'data' = '[{"_talents"etc'
Is this relevant?
MySQL / PHP problem with " and '
Which implys you may have magic Quotes enabled somewhere to add extra backslashes (which may explain why you get odd behaviout on your server but not your local machine)?
The different behaviour on both platforms implies some configuration issue on the server to me (you sure they are the same version?) I'm reaching a bit here though.
I found out it seems to have been my version of webmin adding it in on the console... d'oh
When I ran the query from PHP it went through perfectly.
Many thanks though.