-1

I am trying for user login and registration forms in Android. From past 5 days, I am trying it. I am not able to get it. Can anyone help me please? This is my code user_control.php. I am including the connection.php in 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");

    }
    }

While I am running with postman software by Chrome I am getting the error as I am getting syntax error:

unexpected 'header' (T_STRING) in   http://localhost:80/opt/lampp/htdocs/user_control.php
Biffen
  • 6,249
  • 6
  • 28
  • 36

2 Answers2

0

Remove the space in your line 1. Should looks like:

<?php
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
Néstor
  • 416
  • 4
  • 10
-2

Try to comment:

//header('Content-Type: application/json'); /* used for including json format*/

Source: https://stackoverflow.com/a/20620606/2381906

Community
  • 1
  • 1
Néstor
  • 416
  • 4
  • 10