<?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');
				

$name=trim($_POST['name']);
$phone=trim($_POST['phone']);
$emaile=trim($_POST['email']);
$password=trim($_POST['password']);
$divition=trim($_POST['divition']);
$district=trim($_POST['district']);
$thana=trim($_POST['thana']);
$type=trim($_POST['roll']);

   // check phone number
   $check = "select * from sign_up where  phone = '$phone'";
   $countUser = mysqli_query($conn, $check);
   if(mysqli_num_rows($countUser) > 0) {
        $res->success = 'matching';
        echo json_encode($res);
   } else {
       $sql = "INSERT INTO `sign_up`(`name`, `phone`, `email`, `password`,`divition`, `district`, `thana`, `roll`) VALUES ('$name','$phone','$emaile','$password','$divition','$district','$thana','$type')";
  $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);
   }
    



?>