2016-07-06 6 views
-3

フォームを送信すると、このようなエラーが発生します。私はここで何をしているのか正確に何が間違っているのか分かりません。データの投稿中に次のエラーが発生する

は親切に以下の私のコードを見てください。

SQLSTATE [23000]:整合性制約違反:1048年ル・チャンプ 'r_maritalstatus' NE PEUT ETRE見よ(ヌル)

英語でメッセージは、 "列 'r_maritalstatus'は空ではないかもしれません(ヌル)。"

r_maritalstatusの値を選択すると、他のフィールドにエラーが表示されます。ここで

は、このコードです:

if(!isset($error)){ 
     try { 

     $stmt = $db->prepare('INSERT INTO resumes (memberID, 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 (:memberID, :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(
        ':memberID' => $uid, 
        ':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); 
} 

感謝して、データベーススキーマでよろしく

+0

'$ rmaritalstatus'はどこで定義されますか?プレースホルダとフィールドの大量の山が実際に正しく整列していることを確認しましたが、あなたはどこかを見逃しませんでしたか? –

+2

私のフランス語はちょっと錆びますが、あなたは 'NULL'値を挿入しようとしているフィールドに' NOT NULL'制約を持っていると思います... commeçi:http://stackoverflow.com/questions/20058252/sqlstate23000-integrity-constraint-violation-1048-column-post-can not-be-nu – CD001

+0

imが混乱している、これはフォームの意味でのプレースホルダと関連していますか? – rodrix

答えて

2

は、あなたがNOT NULLとして定義されr_maritalstatus列を持っています。つまり、INSERTを実行するたびに、この列に値を渡す必要があります。省略することも、NULLに設定することもできません。

ソリューション

  1. あなたはいつも何かにr_maritalstatusセットを持っている必要がある場合、これはNOT NULL制約が正しいことを意味し、それはこれについて警告を表示する動作を停止します。 ->executeの前にvar_dump($rmaritalstatus);を実行すると、おそらくNULLになります。したがって、解決策は、INSERTを実行する前にこの変数を検証することです。ここでは、常にレジュームフォームから値を受け取ります。

  2. 常に値があるr_maritalstatusを気にしない場合は、制約を削除する必要があることを意味します。データベースツールにアクセスしてNOT NULLの代わりにNULLに変更してください。

  3. あなたがこれを行うが、あなたは他の多くの分野と同じ問題を抱えていると、あなたがNULLにそれらを変更するの疲れている場合、それはこのコードが非厳密MySQLのモードで動作するように意図したことが最も可能性があります。このモードでは、MySQLはNOT NULLを無視し、省略された文字列フィールドを空に、数値フィールドを0に設定します。別のサーバに移動したり更新した後に突然アプリケーションが壊れた場合は、新しいバージョンへのMySQL。 my.cnfファイルを次の行に変更します。sql_mode="NO_ENGINE_SUBSTITUTION"(最小の厳密モード)。 mysqlサーバを再起動して、やり直してください。

    $db->exec('SET SESSION sql_mode="NO_ENGINE_SUBSTITUTION"'); 
    $db->exec('SET GLOBAL sql_mode="NO_ENGINE_SUBSTITUTION"'); 
    

症状:

それはしばしばとき、開発者がたまたまあなただけのアプリケーションのためにそれを変更したい場合はまた、あなたが$db = new PDO(...)でデータベースに接続した後、これらの権利を追加することができます非厳密モードではデータベーススキーマを作成し、デフォルトで使用するDB管理ツール(たとえば、phpMyAdminなど)によって設定されているNOT NULLに気づかないでください。その後、サーバーに移動したり、新しいバージョンのMySQLにアップグレードして、「1048 Integrity constant violation」や「1364 Fieldにデフォルト値がありません。通常、変更されたモードと関係します。

+0

これはよく作られた有用な答えです。スタックオーバーフローへようこそ! –

関連する問題