MySQL Syntax Error, Can't Figure it Out - mysql

I have the following MySQL statement to insert a lot of data into a lot of columns in a table:
INSERT INTO survey (lang,check,lname,fname,age,dob,dlang1,dlang2,dlang3,dlang4,dlang5,alang1,alang2,alang3,alang4,alang5,expperc1,expperc2,expperc3,expperc4,expperc5,readperc1,readperc2,readperc3,readperc4,readperc5,speakperc1,speakperc2,speakperc3,speakperc4,speakperc5,culture1,culture2,culture3,culture4,culture5,eduyears,eduother,immi, ...
I get the following error when I try to run the statement:
ERROR 1064 (42000): 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 survey
(lang,check,lname,fname,age,dob,dlang1,dlang2,dlang3,dlang4,' at line
1
I thought that to insert data into specific columns I'm supposed to list out all of the column names in ()s, as I've done. Am I missing something here?
For reference, here's the full statement, although the syntax error should have been reached before most of this, right?
INSERT INTO survey (lang,check,lname,fname,age,dob,dlang1,dlang2,dlang3,dlang4,dlang5,alang1,alang2,alang3,alang4,alang5,expperc1,expperc2,expperc3,expperc4,expperc5,readperc1,readperc2,readperc3,readperc4,readperc5,speakperc1,speakperc2,speakperc3,speakperc4,speakperc5,culture1,culture2,culture3,culture4,culture5,eduyears,eduother,immi,emi,correction,level1,ageacq1,agefluent1,ageread1,agereadf1,ycountry1,mcountry1,yfamily1,mfamily1,yschool1,mschool1,speak1,understand1,read1,learnfriends1,learntapes1,learnfamily1,learntv1,learnread1,learnradio1,expofriends1,exporadio1,expofamily1,exporead1,expotv1,expotapes1,accent1,level2,ageacq2,agefluent2,ageread2,agereadf2,ycountry2,mcountry2,yfamily2,mfamily2,yschool2,mschool2,speak2,understand2,read2,learnfriends2,learntapes2,learnfamily2,learntv2,learnread2,learnradio2,expofriends2,exporadio2,expofamily2,exporead2,expotv2,expotapes2,accent2,comb_str,comb_time,wrench_str,wrench_time,snowman_str,snowman_time,raccoon_str,raccoon_time,watch_str,watch_time,horse_str,horse_time,church_str,church_time,iron_str,iron_time,wateringcan_str,wateringcan_time,stroller_str,stroller_time,saw_str,saw_time,wolf_str,wolf_time,stove_str,stove_time,donkey_str,donkey_time,anchor_str,anchor_time,boot_str,boot_time,needle_str,needle_time,pillar_str,pillar_time,thimble_str,thimble_time,window_str,window_time,pencil_str,pencil_time,squirrel_str,squirrel_time,cup_str,cup_time,clothespin_str,clothespin_time,ball_str,ball_time,penguin_str,penguin_time,cow_str,cow_time,salt_str,salt_time,tiger_str,tiger_time,icecreamcone_str,icecreamcone_time,sink_str,sink_time,spider_str,spider_time,cloud_str,cloud_time,fan_str,fan_time,tweezers_str,tweezers_time,pen_str,pen_time,ant_str,ant_time,caterpillar_str,caterpillar_time,spoon_str,spoon_time,pipe_str,pipe_time,snake_str,snake_time,lips_str,lips_time,sword_str,sword_time,palmtree_str,palmtree_time,barn_str,barn_time,orange_str,orange_time,cat_str,cat_time,flower_str,flower_time,apple_str,apple_time,wood_str,wood_time,grasshopper_str,grasshopper_time,leopard_str,leopard_time,lightswitch_str,lightswitch_time,onion_str,onion_time,washingmachine_str,washingmachine_time,nose_str,nose_time,seahorse_str,seahorse_time,windmill_str,windmill_time,sun_str,sun_time,toothbrush_str,toothbrush_time,ruler_str,ruler_time,boat_str,boat_time,elephant_str,elephant_time,crab_str,crab_time,bug_str,bug_time,monkey_str,monkey_time,rope_str,rope_time,heart_str,heart_time,fish_str,fish_time,plug_str,plug_time,jacket_str,jacket_time,helicopter_str,helicopter_time,rhinoceros_str,rhinoceros_time,corkscrew_str,corkscrew_time,envelope_str,envelope_time,wagon_str,wagon_time,belt_str,belt_time,antlers_str,antlers_time,stocking_str,stocking_time,saltshaker_str,saltshaker_time,car_str,car_time,refrigerator_str,refrigerator_time,airplane_str,airplane_time,pig_str,pig_time,cherry_str,cherry_time,circle_str,circle_time,stool_str,stool_time,gun_str,gun_time,balloon_str,balloon_time,crib_str,crib_time,vest_str,vest_time,snail_str,snail_time,hippo_str,hippo_time,tennisracket_str,tennisracket_time,fence_str,fence_time,gorilla_str,gorilla_time,bear_str,bear_time,chest_str,chest_time,brush_str,brush_time,ostrich_str,ostrich_time,priest_str,priest_time,mountain_str,mountain_time,x_str,x_time,chisel_str,chisel_time,bed_str,bed_time,eye_str,eye_time,basket_str,basket_time,asparagus_str,asparagus_time,scissors_str,scissors_time,couch_str,couch_time,flashlight_str,flashlight_time,box_str,box_time,grave_str,grave_time,watermelon_str,watermelon_time,knife_str,knife_time,leg_str,leg_time,blouse_str,blouse_time,violin_str,violin_time,rock_str,rock_time,tomato_str,tomato_time,parachute_str,parachute_time,dustpan_str,dustpan_time,vase_str,vase_time,sewingmachine_str,sewingmachine_time,house_str,house_time,backpack_str,backpack_time,door_str,door_time,diaper_str,diaper_time,curtains_str,curtains_time,nail_str,nail_time,bowl_str,bowl_time,dresser_str,dresser_time,butterfly_str,butterfly_time,ladle_str,ladle_time,toaster_str,toaster_time,leaf_str,leaf_time,cannon_str,cannon_time,square_str,square_time,whistle_str,whistle_time,triangle_str,triangle_time,glasses_str,glasses_time,skateboard_str,skateboard_time,skunk_str,skunk_time,clown_str,clown_time,dime_str,dime_time,grapes_str,grapes_time,ironingboard_str,ironingboard_time,closet_str,closet_time,safetypin_str,safetypin_time,hair_str,hair_time,shirt_str,shirt_time,rollingpin_str,rollingpin_time,bell_str,bell_time,gas_str,gas_time,hook_str,hook_time,glass_str,glass_time,bucket_str,bucket_time,worm_str,worm_time,top_str,top_time,garbage_can_str,garbage_can_time,barrel_str,barrel_time,strawberry_str,strawberry_time,well_str,well_time,ax_str,ax_time,seal_str,seal_time,necklace_str,necklace_time,cake_str,cake_time,ring_str,ring_time,genie_str,genie_time,beard_str,beard_time,pitcher_str,pitcher_time,pear_str,pear_time,tape_str,tape_time,pliers_str,pliers_time,giraffe_str,giraffe_time,train_str,train_time,owl_str,owl_time,celery_str,celery_time,wheel_str,wheel_time,bricks_str,bricks_time,skirt_str,skirt_time,truck_str,truck_time,clock_str,clock_time,bicycle_str,bicycle_time,egg_str,egg_time,kettle_str,kettle_time,shoe_str,shoe_time,lettuce_str,lettuce_time,lawnmower_str,lawnmower_time,tent_str,tent_time,tie_str,tie_time,table_str,table_time,lemon_str,lemon_time,wheelchair_str,wheelchair_time,scale_str,scale_time,peacock_str,peacock_time,frying_pan_str,frying_pan_time,spiderweb_str,spiderweb_time,broom_str,broom_time,tear_str,tear_time,screwdriver_str,screwdriver_time,sled_str,sled_time,arm_str,arm_time,peach_str,peach_time,lock_str,lock_time,bread_str,bread_time,thumb_str,thumb_time,chicken_str,chicken_time,teapot_str,teapot_time,fishingpole_str,fishingpole_time,football_str,football_time,deer_str,deer_time,turtle_str,turtle_time,pumpkin_str,pumpkin_time,peas_str,peas_time,zebra_str,zebra_time,paintbrush_str,paintbrush_time,chain_str,chain_time,eskimo_str,eskimo_time,rollerskate_str,rollerskate_time,peanut_str,peanut_time,vacuum_str,vacuum_time,football_helmet_str,football_helmet_time,cactus_str,cactus_time,doorknob_str,doorknob_time,tv_str,tv_time,sailboat_str,sailboat_time,piano_str,piano_time,suitcase_str,suitcase_time,mosquito_str,mosquito_time,lipstick_str,lipstick_time,nut_str,nut_time,purse_str,purse_time,sandwich_str,sandwich_time,mitten_str,mitten_time,kangaroo_str,kangaroo_time,crown_str,crown_time,flag_str,flag_time,button_str,button_time,cigarette_str,cigarette_time,baseball_bat_str,baseball_bat_time,ghost_str,ghost_time,turkey_str,turkey_time,hammer_str,hammer_time,saddle_str,saddle_time,bird_str,bird_time,fork_str,fork_time,hand_str,hand_time,mixer_str,mixer_time,recordplayer_str,recordplayer_time,swan_str,swan_time,rockingchair_str,rockingchair_time,mask_str,mask_time,guitar_str,guitar_time,fly_str,fly_time,duck_str,duck_time,floor_str,floor_time,bottle_str,bottle_time,hat_str,hat_time,fox_str,fox_time,camel_str,camel_time,net_str,net_time,typewriter_str,typewriter_time,mushroom_str,mushroom_time,igloo_str,igloo_time,panda_str,panda_time,paint_str,paint_time,fishtank_str,fishtank_time,ladder_str,ladder_time,cigar_str,cigar_time,artichoke_str,artichoke_time,hanger_str,hanger_time,flute_str,flute_time,telephone_str,telephone_time,policeman_str,policeman_time,key_str,key_time,carrot_str,carrot_time,pot_str,pot_time,potato_str,potato_time,zipper_str,zipper_time,pants_str,pants_time,bone_str,bone_time,fire_str,fire_time,ear_str,ear_time,toilet_str,toilet_time,doll_str,doll_time,pineapple_str,pineapple_time,lion_str,lion_time,binoculars_str,binoculars_time,hamburger_str,hamburger_time,walnut_str,walnut_time,camera_str,camera_time,chair_str,chair_time,ashtray_str,ashtray_time,bee_str,bee_time,umbrella_str,umbrella_time,globe_str,globe_time,harp_str,harp_time,motorcycle_str,motorcycle_time,lobster_str,lobster_time,sock_str,sock_time,slide_str,slide_time,alligator_str,alligator_time,rabbit_str,rabbit_time,block_str,block_time,arrow_str,arrow_time,banana_str,banana_time,crackers_str,crackers_time,sheep_str,sheep_time,thread_str,thread_time,puzzle_str,puzzle_time,sweater_str,sweater_time,radish_str,radish_time,porcupine_str,porcupine_time,foot_str,foot_time,bus_str,bus_time,lamp_str,lamp_time,kite_str,kite_time,desk_str,desk_time,trumpet_str,trumpet_time,rake_str,rake_time,canopener_str,canopener_time,wheat_str,wheat_time,railroadtracks_str,railroadtracks_time,lightbulb_str,lightbulb_time,finger_str,finger_time,tree_str,tree_time,trash_str,trash_time,goat_str,goat_time,star_str,star_time,glove_str,glove_time,swing_str,swing_time,moon_str,moon_time,mouse_str,mouse_time,waffle_str,waffle_time,screw_str,screw_time,eagle_str,eagle_time,dog_str,dog_time,corn_str,corn_time,toe_str,toe_time,coat_str,coat_time,stoplight_str,stoplight_time,road_str,road_time,frog_str,frog_time,earring_str,earring_time,rooster_str,rooster_time,music_str,music_time,book_str,book_time,candle_str,candle_time,drum_str,drum_time)
VALUES ("0","on","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","","2228","","518","","37","","36","","37","","39","","35","","37","","37","","36","","44","","30","","37","","37","","37","","41","","32","","37","","47","","27","","37","","37","","36","","37","","37","","37","","37","","37","","36","","41","","33","","37","","37","","37","","37","","36","","37","","38","","36","","38","","36","","36","","37","","37","","37","","37","","37","","37","","37","","37","","37","","37","","39","","35","","37","","37","","36","","37","","37","","37","","37","","37","","36","","38","","36","","39","","35","","37","","37","","36","","37","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","37","","36","","37","","39","","35","","37","","37","","37","","36","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","39","","35","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","37","","37","","37","","36","","37","","37","","46","","27","","37","","39","","35","","37","","36","","38","","37","","37","","37","","37","","36","","37","","37","","37","","39","","35","","36","","38","","36","","36","","37","","39","","37","","35","","37","","37","","37","","37","","36","","37","","37","","37","","38","","36","","37","","36","","38","","36","","37","","37","","36","","37","","37","","37","","37","","36","","37","","37","","37","","38","","36","","37","","39","","34","","37","","37","","37","","36","","52","","22","","37","","37","","37","","37","","36","","37","","38","","36","","37","","37","","36","","37","","37","","37","","37","","37","","36","","37","","37","","39","","35","","37","","37","","37","","39","","35","","37","","37","","37","","36","","37","","37","","37","","37","","36","","37","","37","","36","","37","","37","","37","","37","","36","","37","","37","","37","","39","","44","","28","","36","","37","","37","","37","","37","","37","","37","","36","","37","","37","","37","","37","","37","","37","","38","","36","","36","","41","","33","","39","","36","","37","","37","","36","","36","","36","","37","","38","","36","","37","","37","","36","","40","","35","","37","","36","","37","","37","","36","","37","","37","","40","","35","","36","","43","","30","","39","","36","","36","","37","","36","","37","","49","","25","","37","","39","","36","","36","","40","","34","","37","","36","","37","","37","","37","","37","","36","","39","","35","","37","","37","","37","","36","","37","","37","","36","","41","","35","","36","","37","","37","","36","","39","","36","","36","","37","","37","","36","","37","","37","","37","","37","","37","","45","","28","","37","","36","","37","","39")
Thanks in advance!

Judging from the error message your immediate problem is caused by fact that you have extra double quotes around your INSERT statement or at least at the begging right in front of INSERT
"INSERT INTO survey (lang,check,lname,fname,age,dob,dlang1,dlang2,dlang3,dlang4,
^^
Other than that check is a reserved word in MySQL, so put it in backticks '`'.
Also you better put values in single quotes rather than double quotes.
That being said your INSERT statement should rather look like
INSERT INTO survey (lang,`check`,lname,...) VALUES ('0','on','',...)
^ ^ ^ ^ ^ ^ ^ ^^

Please quote all columns name. see exp below
INSERT INTO survey (`lang`,`check`,`lname`,`fname`,`age`,`dob`...

Related

MySQL "INSERT INTO position" fails

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.

SQL ERROR - Error sql syntax

I am getting an error that I dont know how to deal with.
I am running the same code without issue for another column but for this column it refuses to work.
SELECT * FROM Players WHERE Character = 'momo' // This one wont work
SELECT * FROM Players WHERE Class = 'Fighter' // this one works
Character is a VARCHAR and Class is TEXT. I have tried changing Character to TEXT and I still get the same issue. The value 'momo' exists in the table.
ERROR: Couldn't connect to server. 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 '= ''' at line 1
Edit:
I am editing this incase someone find this and wants to know how it was fixed. User by the name of ueerdo Pointed out that I should use quotations and when I did, it worked. So I started looking into why it happened and I found out the SQL reserves Character for something else so it is something that I can't use unless it is in quotations.
It is best to delimit identifiers to prevent possible collision with reserved words and keywords.
SELECT * FROM `Players` WHERE `Character` = 'momo'

I am getting this error ?? can anyone advise why I can not see why

SQL query:
"INSERT INTO `ORDER_HEADER` (`order_ID`, `customer_ID`, `time_of_sale`, `net_total`)
VALUES (NULL, {$_SESSION['customer_ID']}, NOW(), '{$_SESSION['grand_total']}')"
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 '"INSERT INTO ORDER_HEADER (order_ID, customer_ID, time_of_sale, `net_tot' at line 1
I think you have an extra quote at the beginning,from your error.You have to look just before mysql tells you about the error in your query.
'"INSERT
Hey bro you forgot to enclose this value within single quotes
(') {$_SESSION['customer_ID']}
Hence you r getting syntax error
Happy Coding :)
According to your error you seem to have an extra quote in the beginning. You could also be having an issue with the string concatenation of your $_SESSION variables.
Have you tried using php PDO statements? The will make your life MUCH easier, and they can be used to prevent SQL injection attacks and generally just make your code more secure.
Here's my favorite tutorial:
http://net.tutsplus.com/tutorials/php/php-database-access-are-you-doing-it-correctly/
And the docs:
http://php.net/manual/en/book.pdo.php

MySQL syntax variation

I am learning Php/MySQL from online tutorials (not that I expect you to watch it, but as a reference: http://www.youtube.com/watch?v=rJ3tDQfJt4k)
I am using MySQL 5.5.27 through phpMyAdmin 3.5.2.2
In the tutorial, this code is given (and works):
INSERT INTO 'posts' ('title', 'contents') VALUES('this is the first post', 'Yes it is.')
However, I receive this error message:
"#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..."
This syntax (which I found through trial and error) works for me:
INSERT INTO posts (title, contents) VALUES('this is the first post', 'Yes it is.')
I would like someone to explain why this is the case, and how to identify correct syntax - or to be linked to some documentation which would make this distinction comprehensible for a beginner. (I am unlikely to be able to follow the manual at this point in my learning.) Thanks for any help you can provide.
MySQL identifiers (column and table names) are optionally encased by backticks "`", not single quotes. The video is a little blurry and I can see why you would mistake them.
Try:
INSERT INTO `posts` (`title`, `contents`) VALUES('this is the first post', 'Yes it is.')
By default, identifiers can be escaped with backquotes, not single quotes. The default condition is due to the sql_mode mysqld starts with.
You could use double quotes if you configure ANSI_QUOTES for the sql_mode.
I wrote about this in the DBA StackExchange : How to convert MySQL Keyword to normal column

Please resolve the syntax error in the mysql insert query

I am using mysql 5.5.27
At places where it looks like double quotes are two single quotes closer together, and they are actually null values in the excel sheetin the db.
I get the following error,
com.mysql.jdbc.exceptions.jdbc4.MySQLS… 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 'CASE,lname,fname,gender,dob,ssn,… at line 1
the actual query is
Insert into
work(CASE,lname,fname,gender,dob
"CASE" is a reserved word : See http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
You may escape it :
Insert into child(`CASE`,LASTNAME,FIRSTNAME,GENDER,DOB… American','1689 Crucible Street','','Pittsburgh','PA','15210','(4…
But I would personally prefer renaming the column.
CASE is a reserved word ... quote it ..
For mysql:
insert into tableName values()
Anyway you have SQL syntax errors:
Insert into child(CASE,LASTNAME,FIRSTNAME,GENDER,DOB… American','1689 Crucible Street','','Pittsburgh','PA','15210','(4…
Case is a reserwed word: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html
In DOB… American' you miss a ' ('DOB… American')