As far as I can see my SQL code is formatted correctly, it seems to just be refusing to insert into the database.
this is my code:
INSERT INTO `writings`(`cover`, `pages`) VALUES(['test'], [10]);
i also tried
INSERT INTO `writings`(cover, pages) VALUES(['test'], [10]);
&
INSERT INTO `writings`(cover, pages) VALUES('test', 10);
I encounter this 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 '['test'], [10])' at line 1 "
table name is correct, aswell as column names.
Any help would be fantastic! :)
As already pointed out on the comment
MySQL does not use [] around values
So you should try this way
INSERT INTO `writings`(`cover`, `pages`) VALUES('test', 10);
OR if you want the cover and pages value as an string of array notation
INSERT INTO `writings`(`cover`, `pages`) VALUES("['test']", "[10]");
First two queries are incorrect as mentioned above.
Third query is absolutely correct and must work. If it doesn't, try using INSERT ... SET syntax:
INSERT INTO `writings` SET cover = 'test', pages = 10;
INSERT INTO writings(cover, pages) VALUES('test', 10);
This is worked for inserting data in mysql. Basic syntax problem in your query, nothing else. Make sure table name and field name is proper match with database & values are of same datatype you mention while created table.
Please try like this :
Sql Query:
INSERT INTO writings (cover, pages) VALUES ('test', 10);
Related
I am trying to insert data in a table but getting error 1064:
INSERT INTO position(positioncode,description)
VALUES ('5000', 'President');
The error message says:
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 'position(positioncode,description) VALUES ('5000',
'President')' at line 1
I have also insert data in other tables on the same way. Can someone help?
position is the name of a function. Quote it by enclosing it inside backticks:
INSERT INTO `position` (positioncode, description) VALUES ('5000', 'President');
The exact behavior of function name parsing is described here:
Function Name Parsing and Resolution.
The description seems to suggest that:
CREATE TABLE count (i INT) could be an error or not depending on IGNORE SPACE setting
CREATE TABLE count(i INT) is always an error
So instead of guessing, always quote built-in function names.
I'm trying to follow a tutorial on this website, but when I try to insert the below statement I get 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
'`INSERT INTO login_admin (user_name, user_pass)
VALUES
(
‘admin’, SHA(‘a`' at line 7
INSERT INTO login_admin (user_name, user_pass)
VALUES
(
‘swashata’, SHA(‘swashata’)
)
INSERT INTO login_admin (user_name, user_pass)
VALUES
(
‘admin’, SHA(‘admin’)
)
You're trying to run two queries at once, not one. Each INSERT statement is a separate query. You have to separate queries with a delimiter (;).
In fact, unless you have some bad settings on your server (allowing multiple queries at once), you can't even do that and need to run them as two separate queries, or combine them using multiple VALUES lists.
Also, please note that you cannot use tick marks (‘) to indicate a string value. You need to use single quotes (') instead.
The best approach is to rewrite your queries as:
INSERT INTO login_admin (`user_name`, `user_pass`) VALUES
( 'swashata', SHA('swashata') ),
( 'admin', SHA('admin') )
Finally, I really hope you aren't using SHA to generate passwords. That's not secure. Use PHP's built-in password functionality.
I'm using the below SQL statement in a OLEDB command transformation.
Syntax 1:
INSERT INTO dbo.Table1 (col1,col2)
SELECT ?, 22 FROM dbo.Table1
But, it fails with an error:
syntax error , permission violation or other nonspecific error.
However, this syntax works fine.
Syntax 2:
INSERT INTO dbo.Table1 (col1,col2)
values (?,?)
Is Syntax 1 not supported by SSIS?
There's a hack to make it work & Martina White (http://dataqueen.unlimitedviz.com/) helped me out with it.
Below is her transcript:
I can duplicate your issue. There is a funky issue with OLE DB Command. When I write the query with the Values statement commented out, the Syntax 1 query as you have written it does work. When I remove the commented out statement it does not work. It seems to want the word Values() in there, regardless of whether it is commented out.
Try this and see if you get the same behaviour. If so, this should work successfully for you.
INSERT INTO dbo.Table1 (col1,col2)
--Values()
SELECT ?, 22 FROM dbo.Table1
No, it is not; in fact, it's not supported by any database that I'm aware of. You cannot parameterize the columns of a SELECT statement.
I'm using the SQL window in phpMyAdmin (3.5.7) to insert rows into a MySql table, but am having problems with the syntax checker. It's running on Windows Server 2003.
If I click the "INSERT" button to generate a template, then overtype the values in the template, there is no problem. However I because I need to populate a large number of rows I have auto-generated INSERT statements using Excel, pasted them into a text editor, and then pasted them into the same phpMyAdmin SQL window. The results are baffling...
The statement below (generated using Excel/text editor/copy&paste) gives an 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 ''timeslot' ('slot_no', 'slot_starttime') VALUES (3,'00:30')' at
line 1
INSERT INTO 'timeslot' ('slot_no', 'slot_starttime') VALUES (2,'00:15')
The statement below is fine however (it was constructed by clicking the INSERT button on the SQL window then over-typing the text in the template:
INSERT INTO `timeslot`(`slot_no`, `slot_starttime`) VALUES (2,'00:15')
I have copied and pasted both statements into this post directly from the phpMyAdmin window. They look pretty much the same to me, so I can't understand why the first one fails.
???
If you have pasted the results directly as you say, there is a syntax error.
In MYSQL you cannot enclose field or table names using the apostrophe sign. Rather you've got to use the BACK-QUOTE (on the tilde key)
So the following is WRONG:
INSERT INTO 'timeslot' ('slot_no', 'slot_starttime') VALUES (2,'00:15')
And the folowing is CORRECT:
INSERT INTO `timeslot` (`slot_no`, `slot_starttime`) VALUES (2,'00:15')
And even the following is CORRECT (without the back-quotes):
INSERT INTO timeslot (slot_no, slot_starttime) VALUES (2,'00:15')
The common single quote (') is used only for VALUES in an SQL statement.
I want to extract a text field from a database and insert it into some other database. So while extracting I used the REPLACE(message_text,'\'', '"') while selecting the test. I gave me an error. I changed that from my select statement and did it while initiating the global variable.
etl.globals['message_text'] = message_text;
still I'm getting an error at the insert statement
insert into lcs_al_user_likes(user_id,liked_user_id,post_content,loop_id) values('${etl.globals['posted_by']}','${etl.globals['liked_user_id']}','${etl.globals['message_text']}',?batchLoopCounter);
saying
*You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'message_text']}')' at line 1*
I think it is not getting the global variable. That I say because when i print its value using log it just gives me
${etl.globals['message_text']}
as output. So please help me out here.
<query connection-id="lcsDBConnection">
SELECT forum_topic_post_id AS forum_topic_post_id, posted_by AS posted_by,message_text as message_text FROM lcs_tbl_forum_topic_post WHERE like_count>0 LIMIT ?batchSize OFFSET ?queryCounter ;
<script connection-id="jexl">
etl.globals['forum_topic_post_id'] = forum_topic_post_id;
etl.globals['posted_by'] = posted_by;
etl.globals['message_text'] = message_text.replace('\'', '"');
</script>
It looks like the problem is in INSERT statement, you should use prepared statement
parameters escaping:
INSERT INTO lcs_al_user_likes(user_id,liked_user_id,post_content,loop_id) values(?{etl.globals['posted_by']},?{etl.globals['liked_user_id']},?{etl.globals['message_text']},?batchLoopCounter);
BTW As I understand, your original problem was quotes breaking the insert statement, so in this case with ?{parameter} syntax you don't need to use replace(...) function at all.