lovephp Posted July 6, 2016 Share Posted July 6, 2016 i keep getting error like this when i submit form SQLSTATE[23000]: Integrity constraint violation: 1048 Le champ 'r_maritalstatus' ne peut être vide (null) and if i select a value in r_maritalstatus then error shows for other field here is this code if(!isset($error)){ try { $stmt = $db->prepare('INSERT INTO resumes (r_name,r_email,r_mobile,r_address,r_dob,r_maritalstatus,r_nationality,r_religion,r_sex,r_objective,r_languagesknown,r_hobbies,r_expcategory,r_exptype,r_exptitle1,r_expcompany1,r_expcity1,r_expfrom1,r_expto1,r_expdescription1,r_exptitle2,r_expcompany2,r_expcity2,r_expfrom2,r_expto2,r_expdescription2,r_exptitle3,r_expcompany3,r_expcity3,r_expfrom3,r_expto3,r_expdescription3,r_exptitle4,r_expcompany4,r_expcity4,r_expfrom4,r_expto4,r_expdescription4,r_exptitle5,r_expcompany5,r_expcity5,r_expfrom5,r_expto5,r_expdescription5,r_eduinstname1,r_edudegree1,r_edustudyfield1,r_educity1,r_edupassed1,r_eduinstname2,r_edudegree2,r_edustudyfield2,r_educity2,r_edupassed2,r_eduinstname3,r_edudegree3,r_edustudyfield3,r_educity3,r_edupassed3,r_eduinstname4,r_edudegree4,r_edustudyfield4,r_educity4,r_edupassed4,r_eduinstname5,r_edudegree5,r_edustudyfield5,r_educity5,r_edupassed5,r_skill1,r_skillexp1,r_skill2,r_skillexp2,r_skill3,r_skillexp3,r_skill4,r_skillexp4,r_skill5,r_skillexp5) VALUES (:r_name, :r_email, :r_mobile, :r_address, :r_dob, :r_maritalstatus, :r_nationality, :r_religion, :r_sex, :r_objective, :r_languagesknown, :r_hobbies, :r_expcategory, :r_exptype, :r_exptitle1, :r_expcompany1, :r_expcity1, :r_expfrom1, :r_expto1, :r_expdescription1, :r_exptitle2, :r_expcompany2, :r_expcity2, :r_expfrom2, :r_expto2, :r_expdescription2, :r_exptitle3, :r_expcompany3, :r_expcity3, :r_expfrom3, :r_expto3, :r_expdescription3, :r_exptitle4, :r_expcompany4, :r_expcity4, :r_expfrom4, :r_expto4, :r_expdescription4, :r_exptitle5, :r_expcompany5, :r_expcity5, :r_expfrom5, :r_expto5, :r_expdescription5, :r_eduinstname1, :r_edudegree1, :r_edustudyfield1, :r_educity1, :r_edupassed1, :r_eduinstname2, :r_edudegree2, :r_edustudyfield2, :r_educity2, :r_edupassed2, :r_eduinstname3, :r_edudegree3, :r_edustudyfield3, :r_educity3, :r_edupassed3, :r_eduinstname4, :r_edudegree4, :r_edustudyfield4, :r_educity4, :r_edupassed4, :r_eduinstname5, :r_edudegree5, :r_edustudyfield5, :r_educity5, :r_edupassed5, :r_skill1, :r_skillexp1, :r_skill2, :r_skillexp2, :r_skill3, :r_skillexp3, :r_skill4, :r_skillexp4, :r_skill5, :r_skillexp5)'); $stmt->execute(array( ':r_name' => $rname, ':r_email' => $remail, ':r_mobile' => $rmobile, ':r_address' => $raddress, ':r_dob' => $rdob, ':r_sex' => $rsex, ':r_maritalstatus' => $rmaritalstatus, ':r_nationality' => $rnationality, ':r_religion' => $rreligion, ':r_objective' => $robjective, ':r_languagesknown' => $rlanguagesknown, ':r_hobbies' => $rhobbies, ':r_expcategory' => $rjobcategory, ':r_exptype' => $rjobtype, ':r_exptitle1' => $rjobtitle1, ':r_expcompany1' => $rjobcompany1, ':r_expcity1' => $rjobcity1, ':r_expfrom1' => $rjobfrom1, ':r_expto1' => $rjobto1, ':r_expdescription1' => $rjobdescription1, ':r_exptitle2' => $rjobtitle2, ':r_expcompany2' => $rjobcompany2, ':r_expcity2' => $rjobcity2, ':r_expfrom2' => $rjobfrom2, ':r_expto2' => $rjobto2, ':r_expdescription2' => $rjobdescription2, ':r_exptitle3' => $rjobtitle3, ':r_expcompany3' => $rjobcompany3, ':r_expcity3' => $rjobcity3, ':r_expfrom3' => $rjobfrom3, ':r_expto3' => $rjobto3, ':r_expdescription3' => $rjobdescription3, ':r_exptitle4' => $rjobtitle4, ':r_expcompany4' => $rjobcompany4, ':r_expcity4' => $rjobcity4, ':r_expfrom4' => $rjobfrom4, ':r_expto4' => $rjobto4, ':r_expdescription4' => $rjobdescription4, ':r_exptitle5' => $rjobtitle5, ':r_expcompany5' => $rjobcompany5, ':r_expcity5' => $rjobcity5, ':r_expfrom5' => $rjobfrom5, ':r_expto5' => $rjobto5, ':r_expdescription5' => $rjobdescription5, ':r_eduinstname1' => $reduinst1, ':r_edudegree1' => $redudegree1, ':r_edustudyfield1' => $redustudyfield1, ':r_educity1' => $reducity1, ':r_edupassed1' => $reduyear1, ':r_eduinstname2' => $reduinst2, ':r_edudegree2' => $redudegree2, ':r_edustudyfield2' => $redustudyfield2, ':r_educity2' => $reducity2, ':r_edupassed2' => $reduyear2, ':r_eduinstname3' => $reduinst3, ':r_edudegree3' => $redudegree3, ':r_edustudyfield3' => $redustudyfield3, ':r_educity3' => $reducity3, ':r_edupassed3' => $reduyear3, ':r_eduinstname4' => $reduinst4, ':r_edudegree4' => $redudegree4, ':r_edustudyfield4' => $redustudyfield4, ':r_educity4' => $reducity4, ':r_edupassed4' => $reduyear4, ':r_eduinstname5' => $reduinst5, ':r_edudegree5' => $redudegree5, ':r_edustudyfield5' => $redustudyfield5, ':r_educity5' => $reducity5, ':r_edupassed5' => $reduyear5, ':r_skill1' => $rskill1, ':r_skillexp1' => $rskillexp1, ':r_skill2' => $rskill2, ':r_skillexp2' => $rskillexp2, ':r_skill3' => $rskill3, ':r_skillexp3' => $rskillexp3, ':r_skill4' => $rskill4, ':r_skillexp4' => $rskillexp4, ':r_skill5' => $rskill5, ':r_skillexp5' => $rskillexp5 )); } catch(PDOException $e) { $error[] = $e->getMessage(); } } echo print_r($_POST); } Quote Link to comment https://forums.phpfreaks.com/topic/301432-getting-error-on-submission/ Share on other sites More sharing options...
Solution Muddy_Funster Posted July 6, 2016 Solution Share Posted July 6, 2016 You are trying to insert null values into columns that you have set in the DB to not accept null values. Either ensure every required field has a value or change the settings in the table if you want to allow null value submission. Quote Link to comment https://forums.phpfreaks.com/topic/301432-getting-error-on-submission/#findComment-1534260 Share on other sites More sharing options...
lovephp Posted July 6, 2016 Author Share Posted July 6, 2016 correct bro its fixed now Quote Link to comment https://forums.phpfreaks.com/topic/301432-getting-error-on-submission/#findComment-1534263 Share on other sites More sharing options...
Jacques1 Posted July 6, 2016 Share Posted July 6, 2016 (edited) Not really. There's a fundamental problem with the way you design your database tables. Instead of storing records as rows, you've somehow decided to copy and paste the corresponding set of columns over and over again. Now you have a gigantic list of numbered columns, most of which problably don't even contain any data. That is not how relational databases work. When you want to add, say, 100 skills to a users, you do not duplicate the skill-related columns in the user table 100 times. That would be insane. You create a separate table for the skills, add 100 rows and link each row to the particular user in the table of users. A clear indicator for design problems is when you start numbering your columns. That doesn't happen in a proper table. So one user has multiple experiences, educational accomplishments and skills? Then you need four tables: users (user_id, name, email, ...) experiences (experience_id, user_id, title, company, ...) educational_accomplishments (educational_accomplishment_id, user_id, institution, degree, field, ...) skills (skill_id, user_id, ...) The experiences, skills etc. are linked to the users via the user_id column. Edited July 6, 2016 by Jacques1 1 Quote Link to comment https://forums.phpfreaks.com/topic/301432-getting-error-on-submission/#findComment-1534266 Share on other sites More sharing options...
lovephp Posted July 7, 2016 Author Share Posted July 7, 2016 Not really. There's a fundamental problem with the way you design your database tables. Instead of storing records as rows, you've somehow decided to copy and paste the corresponding set of columns over and over again. Now you have a gigantic list of numbered columns, most of which problably don't even contain any data. That is not how relational databases work. When you want to add, say, 100 skills to a users, you do not duplicate the skill-related columns in the user table 100 times. That would be insane. You create a separate table for the skills, add 100 rows and link each row to the particular user in the table of users. A clear indicator for design problems is when you start numbering your columns. That doesn't happen in a proper table. So one user has multiple experiences, educational accomplishments and skills? Then you need four tables: users (user_id, name, email, ...) experiences (experience_id, user_id, title, company, ...) educational_accomplishments (educational_accomplishment_id, user_id, institution, degree, field, ...) skills (skill_id, user_id, ...) The experiences, skills etc. are linked to the users via the user_id column. i get you so for every fields i add new tables right? Quote Link to comment https://forums.phpfreaks.com/topic/301432-getting-error-on-submission/#findComment-1534288 Share on other sites More sharing options...
ajoo Posted July 23, 2016 Share Posted July 23, 2016 Hi, I think you are getting it wrong still. Guru Jacques suggested that you add a single table containing all the skills and associate users to those skills. skills (skill_id, user_id, ...) Quote Link to comment https://forums.phpfreaks.com/topic/301432-getting-error-on-submission/#findComment-1534891 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.