Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?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($username,$password) {
- $query = "Select * from users where username = '$username' and password = '$password' ";
- $result = mysqli_query($this->connection, $query);
- if(mysqli_num_rows($result) > 0) {
- $json['success'] = ' Welcome ' .$username;
- echo json_encode($json);
- mysqli_close($this->connection);
- } else {
- $query = "Insert into users(username,password) values ('$username',$password');"
- $is_inserted = mysqli_query($this->connection, $query);
- if ($is_inserted == 1) {
- $json['success'] = ' Account created, welcome '.$username;
- } else {
- $json['error'] = ' Wrong Password ';
- }
- echo json_encode($json);
- mysqli_close($this->connection);
- }
- }
- }
- $user = new User();
- if (isset($_POST['username'],$_POST['password'])) {
- $username = $_POST['username'];
- $username = $_POST['password'];
- if (!empty($username) && !empty($password)) {
- $encrypted_password = md5($password);
- $user -> does_user_exist($username,$encrypted_password);
- } else {
- echo json_encode(" You must fill both fields ");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement