我正在尝试Android中的用户登录和注册表单。从过去5天开始,我正在尝试。我无法得到它。有人可以帮我吗?这是我的代码user_control.php
。我在connection.php
中加入了user_control.php
。
<? php
class user {
private $db;
private $connection;
/* The below one is the consttructor*/
function __construct() {
header('Content-Type: application/json'); /* used for including json format*/
require_once 'connection.php';
$this->db = new DB_Connection();
$this->connection = $this->db->get_connection();
}
public function does_user_exist($email,$password) {
$query = "Select * from userss 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 userss(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");
}
}
当我使用Chrome运行postman软件时,我收到错误,因为我收到语法错误:
unexpected 'header' (T_STRING) in http://localhost:80/opt/lampp/htdocs/user_control.php
答案 0 :(得分:0)
删除第1行中的空格1.应如下所示:
<?php
答案 1 :(得分:-2)
尝试发表评论:
//header('Content-Type: application/json'); /* used for including json format*/