2

この単純なphpスクリプトを取得しました。それがすることは次のとおりです。

  1. ユーザーは給与を入力します。
  2. ユーザーは、ドロップダウン リストからメンバーシップ タイプを選択します。
  3. php スクリプトは単純なロジックを実行します。ユーザーがメンバーシップ タイプを EMPLOYED として選択すると、適切な応答が実行されて返されます (理解を深めるために、私の関数を参照してください)。
  4. ユーザーが「自営業、任意のメンバー、または OFW」を選択すると、割り当てられた機能を再び実行します。

私の問題は何ですか:

プログラムはエラーなしで実行されています。問題は、何も表示されないことです。あたかも何も起こっていないかのように。問題に見えるのは?

ところで、私は 8 時間前に PHP を学んだばかりで、まだ初心者の段階でこれらのことを試しています。私を助けてください。これで数時間立ち往生しました。優しくしてください:)

<form method="POST">
Salary: <input id="salarytext" type="text" name="salary" onkeypress="return isNumberKey(event)"><br>
Membership Type:
<select name="membershiptype">
        <option value="employed">Employed</option>
        <option value="SE">Self Employed</option>
        <option value="VM">Voluntary Member</option>
        <option value="OFW">OFW</option>
</select>

<br/>

<input type="submit" />

</form>

<?php

$a = (isset($_POST['salary'])) ? $_POST['salary'] : '';
$b = (isset($_POST['membershiptype'])) ? $_POST['membershiptype'] : '';

function employed () {

        if (empty ($a)) {echo "";}
        elseif ($a<1000) {echo "Your Salary for the Period is $a. <br> You didn't reach the minimum compensation for the period. No SSS Contribution Deduction.";}
        elseif ($a <1249.99) {echo "Your ER is 80.7 and Your EE is 33.3 sevmofw"; }
        elseif ($a <1749.99) {echo "Your ER is 116 and Your EE is 50";}
        elseif ($a <2249.99) {echo "Your ER is 151.3 and Your EE is 66.7";}
        elseif ($a <2749.99) {echo "Your ER is 186.7 and Your EE is 83.3";}
        elseif ($a <3249.99) {echo "Your ER is 222 and Your EE is 100";}
        elseif ($a <3749.99) {echo "Your ER is 257.3 and Your EE is 116.7";}
        elseif ($a <4249.99) {echo "Your ER is 292.7 and Your EE is 133.3";}
        elseif ($a <4749.99) {echo "Your ER is 328 and Your EE is 150";}
        elseif ($a <5249.99) {echo "Your ER is 363.3 and Your EE is 166.7";}
        elseif ($a <5749.99) {echo "Your ER is 398.7 and Your EE is 183.3";}
        elseif ($a <6249.99) {echo "Your ER is 434 and Your EE is 200";}
        elseif ($a <6749.99) {echo "Your ER is 469.3 and Your EE is 216.7";}
        elseif ($a <7249.99) {echo "Your ER is 504.7 and Your EE is 233.3";}
        elseif ($a <7749.99) {echo "Your ER is 540 and Your EE is 250";}
        elseif ($a <8249.99) {echo "Your ER is 575.3 and Your EE is 266.7";}
        elseif ($a <8749.99) {echo "Your ER is 610.7 and Your EE is 283.3";}
        elseif ($a <9249.99) {echo "Your ER is 646 and Your EE is 300";}
        elseif ($a <9749.99) {echo "Your ER is 681.3 and Your EE is 316.7";}
        elseif ($a <10249.99) {echo "Your ER is 716.7 and Your EE is 333.3";}
        elseif ($a <10749.99) {echo "Your ER is 752 and Your EE is 350";}
        elseif ($a <11249.99) {echo "Your ER is 787.3 and Your EE is 366.7";}
        elseif ($a <11749.99) {echo "Your ER is 822.7 and Your EE is 383.3";}
        elseif ($a <12249.99) {echo "Your ER is 858 and Your EE is 400";}
        elseif ($a <12749.99) {echo "Your ER is 893.3 and Your EE is 416.7";}
        elseif ($a <13249.99) {echo "Your ER is 928.7 and Your EE is 433.3";}
        elseif ($a <13749.99) {echo "Your ER is 964 and Your EE is 450";}
        elseif ($a <14249.99) {echo "Your ER is 999.3 and Your EE is 466.7";}
        elseif ($a <14749.99) {echo "Your ER is 1034.7 and Your EE is 483.3";}
        elseif ($a <=30000) {echo "Your ER is 1090 and Your EE is 500";}
        elseif ($a > 30000) {echo "You reached the maximum. Your ER is 1090 and Your EE is 500";}
}

function  sevmofw () {

        if (empty ($a)) {echo "";}
        elseif ($a<1000) {echo "NOT EMPLOYED. Your Salary for the Period is $a. <br> You didn't reach the minimum compensation for the period. No SSS Contribution Deduction.";}
        elseif ($a <1249.99) {echo "NOT EMPLOYED. Your ER is 80.7 and Your EE is 33.3 sevmofw"; }
        elseif ($a <1749.99) {echo "NOT EMPLOYED. Your ER is 116 and Your EE is 50";}
        elseif ($a <2249.99) {echo "NOT EMPLOYED. Your ER is 151.3 and Your EE is 66.7";}
        elseif ($a <2749.99) {echo "NOT EMPLOYED. Your ER is 186.7 and Your EE is 83.3";}
        elseif ($a <3249.99) {echo "NOT EMPLOYED. Your ER is 222 and Your EE is 100";}
        elseif ($a <3749.99) {echo "NOT EMPLOYED. Your ER is 257.3 and Your EE is 116.7";}
        elseif ($a <4249.99) {echo "NOT EMPLOYED. Your ER is 292.7 and Your EE is 133.3";}
        elseif ($a <4749.99) {echo "NOT EMPLOYED. Your ER is 328 and Your EE is 150";}
        elseif ($a <5249.99) {echo "NOT EMPLOYED. Your ER is 363.3 and Your EE is 166.7";}
        elseif ($a <5749.99) {echo "NOT EMPLOYED. Your ER is 398.7 and Your EE is 183.3";}
        elseif ($a <6249.99) {echo "NOT EMPLOYED. Your ER is 434 and Your EE is 200";}
        elseif ($a <6749.99) {echo "NOT EMPLOYED. Your ER is 469.3 and Your EE is 216.7";}
        elseif ($a <7249.99) {echo "NOT EMPLOYED. Your ER is 504.7 and Your EE is 233.3";}
        elseif ($a <7749.99) {echo "NOT EMPLOYED. Your ER is 540 and Your EE is 250";}
        elseif ($a <8249.99) {echo "NOT EMPLOYED. Your ER is 575.3 and Your EE is 266.7";}
        elseif ($a <8749.99) {echo "NOT EMPLOYED. Your ER is 610.7 and Your EE is 283.3";}
        elseif ($a <9249.99) {echo "NOT EMPLOYED. Your ER is 646 and Your EE is 300";}
        elseif ($a <9749.99) {echo "NOT EMPLOYED. Your ER is 681.3 and Your EE is 316.7";}
        elseif ($a <10249.99) {echo "NOT EMPLOYED. Your ER is 716.7 and Your EE is 333.3";}
        elseif ($a <10749.99) {echo "NOT EMPLOYED. Your ER is 752 and Your EE is 350";}
        elseif ($a <11249.99) {echo "NOT EMPLOYED. Your ER is 787.3 and Your EE is 366.7";}
        elseif ($a <11749.99) {echo "NOT EMPLOYED. Your ER is 822.7 and Your EE is 383.3";}
        elseif ($a <12249.99) {echo "NOT EMPLOYED. Your ER is 858 and Your EE is 400";}
        elseif ($a <12749.99) {echo "NOT EMPLOYED. Your ER is 893.3 and Your EE is 416.7";}
        elseif ($a <13249.99) {echo "NOT EMPLOYED. Your ER is 928.7 and Your EE is 433.3";}
        elseif ($a <13749.99) {echo "NOT EMPLOYED. Your ER is 964 and Your EE is 450";}
        elseif ($a <14249.99) {echo "NOT EMPLOYED. Your ER is 999.3 and Your EE is 466.7";}
        elseif ($a <14749.99) {echo "NOT EMPLOYED. Your ER is 1034.7 and Your EE is 483.3";}
        elseif ($a <30000) {echo "NOT EMPLOYED. Your ER is 1090 and Your EE is 500";}
        elseif ($a > 30000) {echo "You reached the maximum. Your ER is 1090 and Your EE is 500";}
}




if ( $_POST['membershiptype'] == 'employed' ){employed();
} elseif ( $_POST['membershiptype'] == 'SE' ){sevmofw();
} elseif ( $_POST['membershiptype'] == 'VM' ){sevmofw();
} elseif ( $_POST['membershiptype'] == 'OFW' ){sevmofw();
}


?>
4

2 に答える 2

3

あなたの$a$bは範囲外です。それらを引数として関数に渡す必要があります。

/* SNIP */
function employed($a, $b) { //Note that the function now accepts two parameters. These will be available in the function.

/* SNIP */
function sevmofw($a, $b) { //Same idea.

/* SNIP */
if ($_POST['membershiptype'] == 'employed') {
    employed($a, $b); //Pass the variables into the function from the outside.
}
elseif ($_POST['membershiptype'] == 'SE') {
    sevmofw($a, $b);
}
elseif ($_POST['membershiptype'] == 'VM') {
    sevmofw($a, $b);
}
elseif ($_POST['membershiptype'] == 'OFW') {
    sevmofw($a, $b);
}
于 2013-07-07T15:29:11.790 に答える
1

実際には、ビジネスとプレゼンテーションのロジックと責任の混合など、コードにはさらに多くの問題があります...

しかし、質問に具体的に言うと、

まず第一にswitch、束の代わりに使用する必要がありますif/elseif

2番、

あなたの関数employed()は何が何であるかについての手がかりがありません$a。引数として指定します。

function employed($a){

   switch(true){

      case $a < 100:

        echo "Your Salary for the Period is $a. <br> You didn't reach the minimum compensation for the period. No SSS Contribution Deduction."   

      break;

      case $a < 1249.99:
         echo "Your ER is 80.7 and Your EE is 33.3 sevmofw";
      break;

      ......
   }
}

それは期待どおりに機能します。

于 2013-07-07T15:29:03.553 に答える