I'm attempting to make use of the OUTPUT line so I don't have to use multiple queries to get information that I've inserted into a table. This is for a basic image uploader project that will rename the images based on their id in the database.
Here's the query I'm using (Using it with PDO)
INSERT INTO `images` (`id`, `type`, `category`, `title`) VALUES (null, :type, :cat, 'Newly uploaded image') OUTPUT INSERTED.id;
-
Processing upload
Error uploading file: 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 'OUTPUT INSERTED.id' at line 1
I've read over a few different tutorials now and I'm really confused as to what the problem is.
OUTPUT is not working in MYSQL.
Use
SELECT LAST_INSERT_ID();
after your insert query
Related
When parsing an xml file and adding it to the database, it displays an error during the script operation:
$sql->exec("INSERT INTO 'example' VALUES('$id', '$title', '$link')");
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 ''example'
VALUES('phpmysqljquery-przeciagnij-z-wy'
at line 1
Can anyone say what is wrong?
You're using the wrong quoting style. Database, table and column identifiers use a different approach:
INSERT INTO `example` VALUES (?,?,?)
Double and single quotes are only for strings. You can't insert stuff into a string.
I have a project on godaddy shared hosting. I am able to run the following query in phpmyadmin successfully: (this is the exact output of the php script)
INSERT INTO payments_facebook(`adset`,`amount`,`date`,`oid` ) VALUES ('6023516764849','3.27','2015-07-25','58');
INSERT INTO payments_facebook(`adset`,`amount`,`date`,`oid` ) VALUES ('6023315002249','200','2015-07-25','53');
INSERT INTO payments_facebook(`adset`,`amount`,`date`,`oid` ) VALUES ('6023221698649','3.43','2015-07-25','52')
I am using the old mysql_query function to insert the data. When I run this query through PHP I get a following error 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 'INSERT INTO payments_facebook(`adset`,`amount`,`date`,`oid` ) VALUES ('602331500' at line 1
but when I run the same query in phpmyadmin it works perfectly.
Here is the structure of the mysql table:
id int(100):
date varchar(30) latin1_swedish_ci
oid int(50)
amount double
adset varchar(200) latin1_swedish_ci
Hopefully someone can help me figure this out, I am not sure if this is a godaddy server limitation or if I have an error in my DB or syntax.
Thank you in advance.
Try this :
$sql = "INSERT INTO payments_facebook(`adset`,`amount`,`date`,`oid` ) VALUES
('6023516764849','3.27','2015-07-25','58'),
('6023315002249','200','2015-07-25','53'),
('6023221698649','3.43','2015-07-25','52')";
I'm trying to import a huge database file to my local dev environment to fix some errors I'm getting on the Magento back-end. I fixed the issue where it wouldn't import based on size, time, and memory. Now I've uncovered this gem of an error which says that my SQL syntax is wrong.
Not sure how that's possible because this is the exact file we're using in production but still, it's driving me nuts. Any help is appreciated.
SQL query:
DELIMITER ; ;
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 'CREATE*/ /!50017 DEFINER=root#localhost/ /*!50003 TRIGGER
trg_catalog_prod' at line 1
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`#`localhost`*/ /*!50003 TRIGGER trg_catalog_product_website_after_insert
AFTER INSERT
ON catalog_product_website FOR EACH ROW
BEGIN
INSERT IGNORE INTO `cataloginventory_stock_status_cl` (`product_id`) VALUES (NEW.`product_id`);
INSERT IGNORE INTO `catalogsearch_fulltext_cl` (`product_id`) VALUES (NEW.`product_id`);
INSERT IGNORE INTO `catalog_product_index_price_cl` (`entity_id`) VALUES (NEW.`product_id`);
I'm working on a private messaging system between users on my site. Here's my query:
$query = "INSERT INTO messages (to, `from`, message) VALUES ('{$user}', '{$username}', '{$message}')";
However, 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 'to, `from`, message) VALUES ('Cheezey', 'Cheezey', 'Enter your message here')' at line 1
I have a nagging feeling that it's a really stupid error on my part, but I can't seem to figure it out.
That's because to is a reserved word in MYSQL, you have to put ` around it, like this:
INSERT INTO(`to`, ...).
INSERT INTO `jos_core_acl_aro`
VALUES (NULL, 'users', LAST_INSERT_ID(), 0, 'Administrator2', 0);
INSERT INTO `jos_core_acl_groups_aro_map`
VALUES (25, '', LAST_INSERT_ID());
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 'INSERT INTO jos_core_acl_groups_aro_map VALUES (25, '', LAST_INSERT_ID())' at line 3*
I am recovering my joomla password. I added user but I can't set his permissions.
Quite likely, the reason is, that you execute two queries separated by ;.
Run both queries one and another separately, shouldn't show up the error.
As others asked, by means of which system do you submit the queries to the database?