I am new to programming so apologies in advance for the misuse of any terms I may have mixed up.
I'm trying to create a very simple login application using php and mysql. There are 3 files: config.php, connection.php and login.php. I am using Postman for testing my inputs and output. However, when I try to run the php script, it gives me this result (updated):
I am not sure what is happening, I've tried to follow a tutorial on youtube and checked if I am missing something but can't find it.. Here are my codes:
config.php:
<?php
define('hostname', 'localhost:80');
define ('username', 'root');
define ('password', 'root');
define ('dbname', 'finger');
?>
connection.php:
<?php
require_once 'config.php';
class DB_connection{
private $connect;
function __construct(){
$this -> connect = mysqli_connect(hostname, username, password, dbname) or die( "DB Connection error");
}
public function get_connection(){
return $this-> connect;
}
}
?>
login.php:
<?php
require_once 'connection.php';
class User{
private $db, $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 passwords = '$password'";
$result = mysqli_query($this->connection, $query);
if (mysqli_num_rows($result) > 0) {
$json['success'] = 'Sign in success!';
$json_encode ($json);
mysqli_close($this ->connection);
#return true;
}
else {
$json['failure'] = 'Sign in Failure, check credentials!';
$json_encode ($json);
mysqli_close($this ->connection);
#return false;
}
}
}
$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(" Please enter both fields! ");
}
}
?>