<?php
require_once('db.php');
// Create connection
//$conn = mysqli_connect($servername, $username, $password, $dbname);
$conn = new mysqli($servername, $username, $password, $dbname);

mysqli_set_charset($conn,'utf8');
				

$Insert_FristName=trim($_POST['name']);
$Insert_Mail=trim($_POST['email']);
$Insert_Phone=trim($_POST['phone']);
$Insert_Password=trim($_POST['password']);




   // check phone number
   $check = "select * from user where  email = '$Insert_Mail'";
   $countUser = mysqli_query($conn, $check);
   if(mysqli_num_rows($countUser) > 0) {
        $res->success = 'matching';
        echo json_encode($res);
   } else {
       $sql = "INSERT INTO `user`(`name`, `email`, `phone`, `password`) VALUES ('$Insert_FristName','$Insert_Mail','$Insert_Phone','$Insert_Password')";
  $run = mysqli_query($conn,$sql);

         $last_id = $conn->insert_id;
         $last_name = $conn->insert_name;

        $res->success = 'Sign Up Successfully';
        $res->id = $last_id;
        $res->name = $last_name;
       echo json_encode($res);
   }
    



?>