(error #1064) You have an error in your SQL syntax
#1

PHP код:
[19:56:48 01/04/18] [ERRORCMySQLQuery::Execute - (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 'SELECT MAX(`id`) FROM `server_item`+1, 'test', 1, 0, 3, 5, 7, 1, 1, 5, 5, 7)' at line 1 (Query: "INSERT IGNORE INTO `server_item` (`id`, `name`, `type`, `required_level`, `attack`, `maxhp`, `maxmp`, `hp_regeneration`, `mp_regeneration`, `jump`, `speed`, `slots`)VALUES (SELECT MAX(`id`) FROM `server_item`+1, 'test', 1, 0, 3, 5, 7, 1, 1, 5, 5, 7)") 
I copied it to the phpmyadmin SQL and it works perfectly manually, how do I do it on this mysql version?
Reply
#2

Quote:

SELECT MAX(`id`) FROM `server_item`+1

? If you want max + 1, then place it before "FROM"
Reply
#3

Quote:
Originally Posted by Misiur
Посмотреть сообщение
? If you want max + 1, then place it before "FROM"
the problem is with the SELECT MAX(`id`) FROM `server_item`, how do I get the highest id of an item?
Reply
#4

I mean in your query you put "+1" after "FROM tablename", that's not right. MAX(`id`) is correct for getting highest id, and if you want + 1 just put it right after MAX, not after FROM part.
Reply
#5

Quote:
Originally Posted by Misiur
Посмотреть сообщение
I mean in your query you put "+1" after "FROM tablename", that's not right. MAX(`id`) is correct for getting highest id, and if you want + 1 just put it right after MAX, not after FROM part.
PHP код:
[20:43:22 01/04/18] [ERRORCMySQLQuery::Execute - (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 'SELECT MAX(`id`) FROM `server_item`, 'test', 1, 0, 3, 5, 7, 1, 1, 5, 5, 7)' at line 1 (Query: "INSERT IGNORE INTO `server_item` (`id`, `name`, `type`, `required_level`, `attack`, `maxhp`, `maxmp`, `hp_regeneration`, `mp_regeneration`, `jump`, `speed`, `slots`)VALUES (SELECT MAX(`id`) FROM `server_item`, 'test', 1, 0, 3, 5, 7, 1, 1, 5, 5, 7)") 
that's without +1, just to show you that is indeed wrong
Reply
#6

Oh, I see. You are trying to insert id via subselecting max id from the table. Well, that's not the way to do it. Is your id column set to `AUTO_INCREMENT`? If yes, then you don't have to pass anything (or pass null to use default value (auto incremented id in this case) if you don't specify which fields you are inserting)
Reply
#7

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Oh, I see. You are trying to insert id via subselecting max id from the table. Well, that's not the way to do it. Is your id column set to `AUTO_INCREMENT`? If yes, then you don't have to pass anything (or pass null to use default value (auto incremented id in this case) if you don't specify which fields you are inserting)
yeah I realized it was related, fixed it, thanks mate
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)