Hi, I am facing a very strange problem in inserting data n MySQL through PHP. There are few fields in my form which are optional when someone leave optional fields blank then program encounter an error like this: Code is: $query_cust="INSERT INTO personal_details VALUES ($cust_id,'$cust_name','$cust_photo','$cust_post_area','$cust_per_add','$cust_force_batt', '$cust_irla','$cust_ppo','$cust_icard','$cust_rank','$dob','$cust_bank_name','$cust_bank_ac','$cust_bank_branch','$cust_pan','$cust_r_phone', '$cust_o_phone','$cust_mob','$cust_email','$cust_flat','$cust_title','$cust_rel','$cust_rel_name','$app_date')"; Query is: INSERT INTO personal_details VALUES (3,'Sumit Kumar','','Only for Defense!','Ballabgarh','Force','','','','','1982-10-10','ICICI','025301529663','Sec 61, Noida','AUKPK539','','','9910888110','','Flat A - 600 Sq. Ft.','Mr.','S/o','Sh. Keshav Singh','2009-06-18') Invalid query: 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 Could someone please help me out in this? Regards, Sumit Kumar
this is a bad practice for writing SQL statement yyou need to specific the fields in you insert statement e.g. insert into table (field1,field2) values ('1','2')
Try this (I don't know if it will make any difference but it never hurts to try): $query_cust=" INSERT INTO `personal_details` VALUES ( $cust_id, \'$cust_name\', \'$cust_photo\', \'$cust_post_area\', \'$cust_per_add\', \'$cust_force_batt\', \'$cust_irla\', \'$cust_ppo\', \'$cust_icard\', \'$cust_rank\', \'$dob\', \'$cust_bank_name\', \'$cust_bank_ac\', \'$cust_bank_branch\', \'$cust_pan\', \'$cust_r_phone\', \'$cust_o_phone\', \'$cust_mob\', \'$cust_email\', \'$cust_flat\', \'$cust_title\', \'$cust_rel\', \'$cust_rel_name\', \'$app_date\' );";