意想不到的& # 39;& lt; & # 39;错误在邮政邮差chrome应用程序


Unexpected '<' error in post by POSTMAN chrome app

//config.php文件

    <?php
    define('hostname', 'localhost');
    define('username', 'root');
    define('password', '');
    define('db_name', 'tutorial2');
    ?>

//connection.php文件
 <?php
    require_once 'config.php';
    class DB_Connection {
    private $connect;
    function _construct(){
        $this->connect = mysqli_connect(hostname, username, password, db_name) or die(" DB connection error");
    }
    public function get_connection() {
        return $this->connect;
    } 
    }
    ?>

//user_control.php文件。我想插入"电子邮件"和密码地址到我的phpMyadmin-mysql数据库。

 <?php
    require_once 'connection.php';
    header('Content-Type: application/json ');
    class User {
    private $db;
    private $connection;
    function __construct(){
        $this->db = new DB_Connection();
        $this->connection = $this->db->get_connection();
    }
    public function does_user_exist($email,$password)
    {
        $query = "Select * from users where email = '$email' and password = '$password'";
        $result = mysqli_query($this->connection, $query);
        if (mysqli_num_rows($result) > 0){
            $json[success] = ' Welcome '.$email;
            echo json_encode($json);
            mysqli_close($this->connection);
        }else {
            $query = " Insert into users(email,password) values ('$email','$password')";
            $is_inserted = mysqli_query($this->connection, $query);
            if ($is_inserted == 1){
                $json[success] = ' Account created, welcome '.$email;
            }else {
                $json[error] = ' Wrong password ';
            }
            echo json_encode($json);
            mysqli_close($this->connection);
        }
    }
    }
    $user = new User();
    if (isset($_POST['email'],$_POST['password'])){
    $email = $_POST['email'];
    $password = $_POST['password'];
    if (!empty($email) && !empty($password)){
        $encrypted_password = md5($password);
        $user -> does_user_exist($email,$encrypted_password);
    }else {
        echo json_encode("You must fill both fields");
    }
    }
    ?>

显示所有的postpost错误。不知何故,我做了清理,但它没有保存"电子邮件"answers"密码"到数据库。

原因如下:

if (!empty($email) && !empty($password)){
    $encrypted_password = md5($password);
    $user -> does_user_exist($email,$encrypted_password);

删除空格:$user->does_user_exist($email,$encrypted_password);

确保在所有文件的开始<?php标记之前没有可用的空白。

还确保您的$json数组键在' (single quotes)内,如下所示:

$json['success'] = ' Welcome '.$email;
$json['error'] = ' Wrong password ';