1

プロセスを続行せずに、エラーメッセージを表示するために新しいページに移動せずに (echo の代わりに die を使用するなど)、エラーメッセージを表示するにはどうすればよいですか? 言い換えれば、ユーザーが新しいページに送られ、「あなたは...」と表示されないようにしたいのですが、このページの下または上にエラーを表示したいのですが、エラーメッセージデータがデータベースに追加されないようにします (次のコマンド、またはいくつかのコマンドを実行します)。

//if submit is clicked
if (isset($_POST['submit'])) {
    //then check if all fields are filled
    if (empty($_POST['username']) | empty($_POST['password']) | empty($_POST['firstname']) | empty($_POST['MI']) | empty($_POST['lastname']) | empty($_POST['email']) | empty($_POST['phonenumber']) | empty($_POST['country']) ) {
        echo('You did not complete all of the required fields. '); }

    $username = $_POST['username'];
    $password = $_POST['password'];
    $usernamesquery = mysqli_query($connection, "SELECT * FROM users WHERE username='$username'");
    if(mysqli_num_rows($usernamesquery) > 0) {
        echo('This username is already taken. ');
    }


} ?>
4

2 に答える 2

1
//if submit is clicked
if (isset($_POST['submit'])) { 
$username = $_POST['username'];
$password = $_POST['password'];
$usernamesquery = mysqli_query($connection, "SELECT * FROM users WHERE username='$username'");
//then check if all fields are filled
if (empty($_POST['username']) | empty($_POST['password']) | empty($_POST['firstname']) | empty($_POST['MI']) | empty($_POST['lastname']) | empty($_POST['email']) | empty($_POST['phonenumber']) | empty($_POST['country']) ) {
    echo('You did not complete all of the required fields. '); }
elseif(mysqli_num_rows($usernamesquery) > 0) {
    echo('This username is already taken. ');
}
else{
  echo "code to submit values to database"
}

} ?>
于 2013-08-02T12:24:42.793 に答える