送信されたフォームの内容に基づいて変数を定義しようとしており、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>';