array无法正常工作

array无法正常工作

我试图在Android应用中创建注册登录功能。我试图通过使用此Php文件将数据从应用程序发送到数据库。但是,当我单击应用程序上的注册按钮时,收到了br /错误。看起来mysqli_fetch_array无法正常工作。有人知道如何解决这个问题吗?谢谢!

<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
    $name = $_POST['name'];
    $username = $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];

    if($name == '' || $username == '' || $password == '' || $email == ''){
        echo 'please fill all values';
    }else{
        require_once('dbConnect.php');
        $sql = "SELECT * FROM users WHERE username='$username' OR email='$email'";
        $result=mysqli_query($con,$sql);
        $check = mysqli_fetch_array($result,MYSQLI_BOTH);
        if(isset($check)){
            echo 'username or email already exist';
        }else{
            $sql = "INSERT INTO users (name,username,password,email) VALUES('$name','$username','$password','$email')";
            if(mysqli_query($con,$sql)){
                echo 'successfully registered';
            }else{
                echo 'oops! Please try again!';
            }
        }
        mysqli_close($con);
    }
 } else{
echo 'error';
}


dbConnect.php

<?php
 define('HOST','localhost');
 define('USER','username');
 define('PASS','password');
 define('DB','database');

 $con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');

最佳答案

我认为您应该删除isset检查。无论如何,它将始终返回true。而是进行计数检查。

if(count($check)){
    echo 'username or email already exist';
}else{
    $sql = "INSERT INTO users (name,username,password,email) VALUES('$name','$username','$password','$email')";
    if(mysqli_query($con,$sql)){
        echo 'successfully registered';
    }else{
        echo 'oops! Please try again!';
    }
}

10-07 14:56