For some reason my code is giving me an error, and I can't figure out why. Here's the error:
INSERT INTO organization (org_name, add_1, add_2, city, state, zip, url, email, phone, contact, hours, file_loc, notes, description, group) VALUES('testmi', '333', '', '', 'MI', '', 'www.blah.com', '', '888-999-2222', '', '', '', '', '', 'Michigan')QUERROR 3You 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) VALUES('testmi', '333', '', '', 'MI', '', 'www.blah.com', ''' at line 1
And here's the code:
$sqlInsertOrg = "INSERT INTO organization (org_name, add_1, add_2, city, state, zip, url, email, phone, contact, hours, file_loc, notes, description, group)
VALUES('".$org_name."', '".$add_1."', '".$add_2."', '".$city."', '".$state."', '".$zip."', '".$url."', '".$email."', '".$phone."', '".$contact."', '".$hours."', '".$file_loc."', '".$notes."', '".$description."', '".$group."')";
GROUP is a reserved keyword in MySQL. Escape it with backticks (`) and you'll be fine.
INSERT INTO organization (org_name, ... `group`) ...
Related
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 6 years ago.
INSERT INTO ry_useraccount
(
'Id',
'UserId',
'FreeAmount',
'PayFrozenAmount',
'WithdrawFrozenAmount',
'CurrentAsset',
'CreateTime',
'UpdateTime'
) VALUES
(
'1',
'52501',
'600',
'0',
'0',
'0',
NOW(),
NOW()
);
If just look at the sql,it is correct,but when I run it,the navicat said
“[SQL]INSERT INTO ry_useraccount('Id', 'UserId', 'FreeAmount',
'PayFrozenAmount', 'WithdrawFrozenAmount', 'CurrentAsset',
'CreateTime', 'UpdateTime') VALUES('1', '52501', '600', '0', '0', '0',
NOW(), NOW()); [Err] 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 ''Id', 'UserId', 'FreeAmount',
'PayFrozenAmount', 'WithdrawFrozenAmount', 'Curren' at line 1”
. I cannot find the reason.I guess that maybe some white space cause the result,but after I delete all the white spaces,it still didn't work.
The single quote are for literal string not for column name (you can use backticks if you need column name with space or with reserved words )
INSERT INTO ry_useraccount(Id, UserId, FreeAmount, PayFrozenAmount, WithdrawFrozenAmount, CurrentAsset, CreateTime, UpdateTime)
VALUES(1, 52501, 600, 0, 0, 0, NOW(), NOW());
I am trying to send some data from Node JS to MySQL using "mysql" module downloaded from NPM.
connection.beginTransaction(function(err) {
if (err) { throw err }
connection.query(sq, function (error, result) {
if (error) {
//return connection.rollback(function() {
throw err
//})
} else {
console.log('data is inserted ... ' + new Date())
}
})
My Query i.e. sq is some thing like that..
INSERT INTO archlb_sales(fiscalYear, fiscalQuarterID, fiscalPeriodID, fiscalWeekID, geo, theater, area, operation, region, country, salesAgen
tName, emailID, arch, technology, subTechnology, tms3, productFamily, scms, totalSales, agentType, salesAgentnumber, softBookingsNet) values ('
2017', '2017Q1', '201701', '2017014', 'Americas', 'Americas-MISCL2', 'Americas-MISCL3', 'Americas-MISCL4', 'Americas-MISCL5', 'UNKNOWN', 'G2C A
djustment Agent', 'UNKNOWN' , 'Collaboration' , 'Collaboration','CLOUD SW' , 'CLD-AUDIO-SW' , 'CWAU', 'OTHER' , -205, 'TEAM AGENT', 'UNKNOWN' ,
'1') ON DUPLICATE KEY UPDATE totalSales = totalSales + -205;
INSERT INTO archlb_sales(fiscalYear, fiscalQuarterID, fiscalPeriodID, fiscalWeekID, geo, theater, area, operation, region, country, sal
esAgentName, emailID, arch, technology, subTechnology, tms3, productFamily, scms, totalSales, agentType, salesAgentnumber, softBookingsNet) val
ues ('2017', '2017Q1', '201701', '2017014', 'Americas', 'Americas-MISCL2', 'Americas-MISCL3', 'Americas-MISCL4', 'Americas-MISCL5', 'UNKNOWN',
'G2C Adjustment Agent', 'UNKNOWN' , 'Collaboration' , 'Collaboration','CLOUD SW' , 'CLD-AUDIO-SW' , 'CWAUCC', 'OTHER' , -123, 'TEAM AGENT', 'UN
KNOWN' , '1') ON DUPLICATE KEY UPDATE totalSales = totalSales + -123;
The values of those variables are read from a text file, which are come correctly
MySQL gives the following error.
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the ri
ght syntax to use near \'INSERT INTO archlb_sales(fiscalYear, fiscalQuarterID, fiscalPeriodID, fiscalWeek\' at line 3
This is the table schema:
You're trying to execute multiple SQL statements in one query, which is disabled unless you explicitly set the multipleStatements option.
I exported a recordset from one database into a csv file, and when I try to import it into another using mysql workbench I keep this this error message:
Executing SQL script in server
ERROR: 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 ' 'Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', '' at line 1
INSERT INTO `TRC`.`horse`
(`horse_id`, `registered_name`, `stable_name`, `arrival_date`, `last_known_location`, `is_ex_racer`, `birth_year`, `death_date`, `horse_comments`, `sex`, `referral_date`, `horse_height`, `arrival_weight`, `passport_no`, `microchip_no`, `is_on_waiting_list`) VALUES
(, 'Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', 'NULL', 'NULL', NULL, NULL, 'NULL', 'NULL', 0)
SQL script execution finished: statements: 29 succeeded, 1 failed
Fetching back view definitions in final form.
Nothing to fetch
Any help would be appreciated as their appears to be no errors as far as I can see.
It's becaose of
VALUES starts with a comma.
You have missed horse_id. If it's Identity Column Then Remove horse_Id
Try like this (If horse_Id is identity)
INSERT INTO `TRC`.`horse`
(`registered_name`, `stable_name`, `arrival_date`, `last_known_location`, `is_ex_racer`, `birth_year`, `death_date`, `horse_comments`, `sex`, `referral_date`, `horse_height`, `arrival_weight`, `passport_no`, `microchip_no`, `is_on_waiting_list`) VALUES
('Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', 'NULL', 'NULL', NULL, NULL, 'NULL', 'NULL', 0)
Or (If Horse_id simple int then try this)
INSERT INTO `TRC`.`horse`
(`horse_id`, `registered_name`, `stable_name`, `arrival_date`, `last_known_location`, `is_ex_racer`, `birth_year`, `death_date`, `horse_comments`, `sex`, `referral_date`, `horse_height`, `arrival_weight`, `passport_no`, `microchip_no`, `is_on_waiting_list`) VALUES
('1','Lord it Over', 'Ben', '1993-03-01', 'TRC', NULL, 1983, '1999-09-01', 'NULL', 'NULL', 'NULL', NULL, NULL, 'NULL', 'NULL', 0)
^^^^ -- Here Horse_Id missing
it seems that you missing your "horse_id" value.
If that field was intended to be the Identity field, then you shouldn't mention that field on Insert Statement right?
If you want MySQL to generate an auto_increment ID for the horse_id field, you should either leave it out of the INSERT statement entirely, or specify NULL for the value in the VALUES list. You can't just leave that value empty in the list.
Your VALUES starts with a comma for some reason
This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 8 years ago.
Thank you for your comments on this error
INSERT INTO donors (
'institution',
'contact_person',
'first_name',
'last_name',
'affiliation',
'picture_link',
'email',
'birthday',
'sex',
'street',
'city',
'state',
'zip'
)
VALUES (
'',
'',
'Claire',
'Bowens',
'employee',
'http://las-americas.org/wp-content/uploads/2010/10/Claire-staff-photo.jpg',
'#',
'yyyy-mm-dd',
'female',
'',
'El Paso',
'Texas',
''
)
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 ''institution', 'contact_person', 'first_name', 'last_name', 'affiliation', 'p' at line 1
To enclose identifiers use backticks => `` `
In your code you used '.
INSERT INTO donors ( `institution`, `contact_person`, `first_name`, `last_name`, `affiliation`?, `picture_link`, `email`, `birthday`, `sex`, `street`, `city`, `state`, `zip`) VALUES ('', '', 'Claire', 'Bowens', 'employee', 'http://las-americas.org/wp-content/uploads/2010/10/Claire-staff-photo.jpg', '#', 'yyyy-mm-dd', 'female', '', 'El Paso', 'Texas', '' )
(Single) Quotes are just used for string literals.
A more detailed answer can be found in this question:
https://stackoverflow.com/a/11321508/1169798
remove the ' from your table fields like this.
INSERT INTO donors (
institution,
contact_person,
first_name,
last_name,
affiliation,
picture_link,
email,
birthday,
sex,
street,
city,
state,
zip
)
VALUES (
'',
'',
'Claire',
'Bowens',
'employee',
'http://las-americas.org/wp-content/uploads/2010/10/Claire-staff-photo.jpg',
'#',
'yyyy-mm-dd',
'female',
'',
'El Paso',
'Texas',
''
)
This is the output I'm getting from the $wpdb->show_errors from Wordpress, and the output of the Query.
WordPress database 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 '1' at line 1]
1
INSERT INTO wp_posts (
to_ping, post_author, pinged, comment_count, post_password, post_excerpt,
post_status, comment_status, ping_status, post_parent, menu_order,
post_content_filtered, post_type, post_mime_type, post_name, post_title,
post_content, post_date, post_date_gmt, post_modified, post_modified_gmt, guid)
VALUES (
'', '', '', '0', '', '', 'draft', 'open', 'open', '0', '0', '', 'page', '',
'test-page', 'This is a test!', 'This is where content goes...',
'2010-12-08 07:38:05', '2010-12-08 07:38:05', '2010-12-08 07:38:05',
'2010-12-08 07:38:05', 'http://localhost/wordpress/?page_id=')
There is literally a "1" on the first line. Remove it. "1" alone is not valid MySQL syntax..
remove 1 at the first line
query is perfect