0

送信されたフォームの内容に基づいて変数を定義しようとしており、MySQL データベースに対してチェックされていますが、preg_match と $variable の一致は連携しません。それらは独立して機能しますが、一緒には機能しません。

すべてのステップで各変数を出力し、送信、比較、取得されたデータが常に存在することを証明しましたが、ifelse ステートメント内で 2 つの変数を比較するときに変数を定義できません: elseif ( !preg_match("/bt/i",$zip ) または $country !== 'アイルランド' )

プロセスは次のとおりです。フォームの送信 -> データベースに対して変数を比較 -> データベースの比較に応じて変数を出力します。

サンプルフォーム送信 (例):

fbid (12345678901)

都市 (ベルファスト)

国 (英国)

zip (BT1 1DS)

これは、問題を引き起こしている (切り詰められた) コードです。

    $country = $location['country']; //good value: Ireland / bad value: Italy(or empty)
    $zip = $location['zip']; //good value: BT1 1DS / bad value: 00(or empty)

    if ($fbid == $id) { //this works
    $confirmpage = '<h3>Sorry, this page is already in the table.</h3>';
    } elseif ( !preg_match("/bt/i",$zip) or $country !== 'Ireland' ) { //confirm location
    $confirmpage = '<h3>This page is not in Northern or Southern Ireland</h3>';
    } else { //success, page can be submitted
    $confirmpage = '<h3>Confirm Page</h3>';
    }

動作しないコードは次のとおりです。

        elseif ( !preg_match("/bt/i",$zip) or $country !== 'Ireland' )

このステートメントを削除すると、残りのスクリプトは正常に動作します。オプション 1 が否定的である場合、このステートメントが適切に配置されている場合、送信されたフォームの zip の先頭に BT が含まれていたり、国としてアイルランドが含まれていたりしても、結果は常にオプション 2 になります。

    $confirmpage = '<h3>This page is not in Northern or Southern Ireland</h3>';
4

3 に答える 3

0

チェックの実行方法を変更してソートしました。代わりに:「condition」または「condition2」の場合、私はifelseを使用してポジティブをチェックしました:

    $confirmpage = '<h3>This page is not in Northern or Southern Ireland</h3>';
    if ($fbid == $id) {
$confirmpage = '<h3>Sorry, this page is already in the table.</h3>';
} elseif ( preg_match("/bt/i",$zip) ) { //BT post code present
$confirmpage = $confirm;
} elseif ($country == 'Ireland') { // //Ireland present
$confirmpage = $confirm;
} else { //confirm page
$confirmpage = '<h3>This page is not in Northern or Southern Ireland</h3>';
于 2012-07-12T13:50:56.797 に答える
0

試す

elseif ( preg_match("/bt/i",$zip) == 1 || $country != 'Ireland' )
于 2012-07-07T17:24:45.723 に答える
0

私は基本的なphpページコードを作成し、あなたのコードにコピーしました.次に、$countryと$zipを手動で適切な値または不適切な値に設定しました.

于 2012-07-07T17:30:30.167 に答える