<?php
$servername = "localhost";
$user = "rings_users";
$password = "?m*~~^_Mk[-{";
$database = "my school";
$con = mysqli_connect($servername, $user, $password, $database);

if($con){
  ?>
  <script>
    alert("connection successful");
  </script>
  <?php
}else{
  ?>
  <script>
    alert("no connection");
  </script>
  <?php
}
?>

    

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    </head>
    <body>
       <?php
  if (isset($_POST['submit'])){
    @$name = mysqli_real_escape_string($con, $_POST['name']);
   @ $email = mysqli_real_escape_string($con, $_POST['email']);
    @$mobile_no = mysqli_real_escape_string($con, $_POST['mobile_no']);

$pass = password_hash($password, PASSWORD_BCRYPT);
    $namequery = "select * from my school where name = '$name'";
    $query = mysqli_query($con, $usernamequery);

    $usernamecount = mysqli_num_rows($query);

    if($usernamecount > 0){
      echo "email already exists";
    }else{
      if($password === $password){

       $insertquery = "insert into  my school(name, email, mobile_no) VALUES ('$name', '$email', '$mobile_no)";

        $iquery = mysqli_query($con, $insertquery);

        if($iquery){
           ?>
    <script>
      alert("inserted successful");
    </script>
    <?php
   }else{
   ?>
   <script>
      alert(" no connection");
    </script>
    <?php
   }
      }else{
        echo "password are not matching";
      }
    }
  }
  ?>

 <div class="container my-4">
    <h1 class="text-center">Login to our website</h1>
    <form action="#" method="POST">
  <div class="form-group col-md-6">
    <label for="username">Username</label>
    <input type="text" class="form-control" id="username" name="username" aria-describedby="emailHelp" required>
    
  </div>
  <div class="form-group col-md-6">
    <label for="password">Password</label>
    <input type="password" class="form-control" id="password" name="password" required>
  </div>
  <div class="form-group col-md-6">
    <label for="email">email</label>
    <input type="email" class="form-control" id="email" name="email" required>
  </div>
  <div class="form-group col-md-6">
    <label for="cpassword">cpassword</label>
    <input type="cpassword" class="form-control" id="cpassword" name="cpassword" required>
  </div>
  <div class="mt-3">
  <button type="submit" name="submit" class="btn btn-primary btn-block">Login</button>
  </div>
</form>
</div>
 <!-- Optional JavaScript; choose one of the two! -->

    <!-- Option 1: Bootstrap Bundle with Popper -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

    <!-- Option 2: Separate Popper and Bootstrap JS -->
    <!--
    <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js" integrity="sha384-IQsoLXl5PILFhosVNubq5LC7Qb9DXgDA9i+tQ8Zj3iwWAwPtgFTxbJ8NT4GN1R8p" crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.min.js" integrity="sha384-cVKIPhGWiC2Al4u+LWgxfKTRIcfu0JTxR+EQDz/bgldoEyl4H0zUF0QKbrJ0EcQF" crossorigin="anonymous"></script>
    -->
  </body>
</html>
