I am confused. I don't know what is the error. On execution I got a message:
" 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 'group(creator,type,name,details,icon)values (6,'information
sharing','test','j' at line 1"
my query is :
INSERT INTO group
(creator, type, name, details, icon) VALUES
(6, 'information sharing', 'test', 'just for testing',
'My friend/group_uploads/pic00_6_0d46839f6371fb84f6b6c682f5fc2c77.jpeg')
this my table specification:
type varchar(1000)
name varchar(1000)
details varchar(1000)
creator bigint(20)
icon varchar(1000)
please help me to correct the error .
group is a reserved word in MySQL. You need to surround it in backticks.
Like this..
insert into `group`(creator, type, name, details, icon) values ('6','information sharing','test','just for testing','My friend/group_uploads/pic00_6_0d46839f6371fb84f6b6c682f5fc2c77.jpeg')
^ ^
Try to avoid having such names for your columns and tables.
Grou is Keywords in MySQL. So use backticks for those.
Try:
INSERT INTO `group`
(`creator`, `type`, `name`, `details`, `icon`) VALUES
(6, 'information sharing', 'test', 'just for testing',
'My friend/group_uploads/pic00_6_0d46839f6371fb84f6b6c682f5fc2c77.jpeg')
Even though by using backticks you can use keywords as table name , It is not recommended to use reserved word as table name
DO NOT DO IT.
Official list of reserved keywords: Reserved Keywords (Transact-SQL)
Related
I cant find what happened to the MYSQL query. It was working fine and today it is throwing 1064 error can anyone help me.
In query browser i am getting 1064 error
and in mysqli_error i am getting "Unknown column 's.firstname' in 'field list'".
query ::
SELECT s.recid userId, s.firstname firstName, s.lastname lastName, s.email email, s.status status
FROM usertable s
WHERE s.email = 'xyz#gmail.com'
AND s.mobile = 'XXXXXXXX'
AND (s.enddate IS NULL OR s.enddate = '0000-00-00' OR s.enddate > '2015-04-08 11:13:34')
Error :
Unknown column 's.firstname' in 'field list'
Check the firstname spelling, white spaces on start and end of the field, if its okay, then remove firstname from query and then try it once.
This will help us to debug.
Check your table has the column firstname
Use below command to check it within query browser
DESC usertable;
Try to wrap everything with backticks (or at least column name called status) and see what happens...
SELECT `s`.`recid` `userId`, `s`.`firstname` `firstName`, `s`.`lastname` `lastName`, `s`.`email` `email`, `s`.`status` `status`
FROM `usertable` `s`
WHERE `s`.`email` = 'xyz#gmail.com'
AND `s`.`mobile` = 'XXXXXXXX'
AND (`s`.`enddate` IS NULL OR `s`.`enddate` = '0000-00-00' OR `s`.`enddate` > '2015-04-08 11:13:34')
Note that you are using status as column name, but even if it isn't declared as keyword it is used in queries like SHOW STATUS...So I will avoid that and change its name to something else. Also using status like this in some versions of phpMyAdmin produced some unexpected results. But when you wrap it with backticks you can use it as column name.
I am trying to do a simple INSERT, but I keep on getting 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 'FROM,TO,ID,CURRENCY1,CURRENCY2,AMOUNT,NOTE,RATE) VALUES('test', 'test2', 'dd', '' at line 2
Here is my code:
mysql_query("INSERT INTO WIRET
(FROM,TO,ID,CURRENCY1,CURRENCY2,AMOUNT,NOTE,RATE) VALUES('$from', '$to', '$ID', '$currency1', '$currency2', '$amount','$note', '$rate') ")
or die(mysql_error());
Why am I getting this error? I copied this script from another area of my site where it works, I just changed the values.
FROM is a reserved word in MySQL (and SQL in general). If you really have a column named FROM you should wrap it with ` (backticks) so the parser knows you mean a name:
INSERT INTO WIRET (`FROM`, TO, ID, CURRENCY1, ...
If your column is named from you have to put it into "`" (backticks) because FROM is also a SQL keyword.
By putting a keyword (FROMhere) into backticks you say "this is not a SQL keyword" to the DBMS.
Example:
INSERT INTO WIRET (`FROM`,TO,ID,...
I keep getting the 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 'exit, openclosed, longshort, target_one, target_two,
target_three, notes, entryd' at line 1
For this php script that I'm trying to run from MYSQL.
$sql = mysql_query("INSERT INTO stockpicks (symbol, entry, exit, openclosed, longshort, target_one, target_two, target_three, notes, entrydate)
VALUES('$symbol','$entry','$exit','$openclosed','$longshort','$target_one','$target_two','$target_three','$notes',now())") or die (mysql_error());
The problem is I see no error. I've checked both this particular line and the lines surrounding. For example I re did the '$var' section which has given me trouble in the past, but that doesn't seem to be the issue. My table structure is as follows
id int(11)
symbol varchar(255)
entry varchar(255)
exit varchar(255)
openclosed varchar(255)
entrydate datetime
longshort varchar(255)
target_one varchar(255)
target_two varchar(255)
target_three varchar(255)
exit is a reserved word. If you want to use it as a column name, quote it in backticks:
`exit`
Try this,
$sql = mysql_query("INSERT INTO stockpicks (symbol, entry, `exit`, openclosed, longshort, target_one, target_two, target_three, notes, entrydate)
VALUES('$symbol','$entry','$exit','$openclosed','$longshort','$target_one','$target_two','$target_three','$notes',now())") or die (mysql_error());
$pid = mysql_insert_id();
Note that escaping your identifiers in MySQL way using backticks decreases portability on a plain place.
I would either use double quotes with ANSI SQL mode enabled, or just give my variables names which are unlikely to be become reserved in future.
exit is a reserved word in mysql.
I have a little problem inserting into a table, here is the code:
mysql_query("INSERT INTO admin_menu (id, title, type, icon, parent, url, order, append, module) VALUES('', 'powerpoint', '0', 'powerpoint.png', '0', 'powerpoint/config', '0', '0', '0' ) ") or die(mysql_error());
it gives me the following 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 'order, append, module) VALUES('', 'powerpoint', '0',
'powerpoint.png', '0', 'pow' at line 1
Any help would be greatly appreciated, thanks!
order is a reserved word. Wrap it in backticks
... url, `order`, append,...
You also shouldn't be using mysql_query.
Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used.
you need to use backticks. order is reserved keyword.
mysql_query("INSERT INTO admin_menu (id, title, type, icon, parent, url, `order`, append, module)
I don't know what's wrong with my syntax, but I'm missing something:
$createrequest = mysql_query("INSERT INTO products_updates_queue (id, kid,
product_version_id, key, ip) VALUES ('$request_id', '$uid', '$version_id',
'$request_key', '$request_ip')");
I receive 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 'key, ip) VALUES ('j4ctveyd0x62', '1', 'z451ah3', 'hqbyu7bhg8za', '64.134.163.2' at line 2"
Can anyone see what I am missing?
I think key is a reserved word, and you should avoid using it as a column name. Try using backticks around it:
$createrequest = mysql_query("INSERT INTO products_updates_queue (id, uid, product_version_id, `key`, ip) VALUES ('$request_id', '$uid', '$version_id', '$request_key', '$request_ip')");
key is a reserved word in MySQL. Avoid it, or wrap it in backticks.
Edit: And I hope you escaped the variables you're putting into that query.