Create a Registration Page using PHP.

Here, we will write a program to create a registration page using PHP in XAMPP software. So all the files need to be stored in the htdocs folder which is in the XAMPP directory, after starting your apache server you can open the file in web browser under local host.

Index.php file

<?php $db=mysqli_connect("localhost","root","",) or die(mysqli_error($db));
mysqli_select_db($db,"registerdb") or die(mysqli_error($db));
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Student Details</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <link href="style.css" rel="stylesheet">
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
<div class="container mt-3">
<div class="form-div">
  <h2 class="text-center">Registration Form</h2>
  <form action="index.php" name="form" method="post" enctype="multipart/form-data">
    <div class="mb-3 mt-3">
      <label for="name">Name</label>
      <input type="text" class="form-control" id="name" placeholder="Enter name" name="name">
    </div>
    <div class="mb-3">
      <label for="course">Course</label>
      <input type="text" class="form-control" id="course" placeholder="Enter Course" name="course">
    </div>
  <div class="mb-3">
      <label for="address">Address</label>
      <input type="text" class="form-control" id="address" placeholder="Enter your address" name="address">
    </div>
  <div class="mb-3">
      <label for="contact">Mobile</label>
      <input type="text" class="form-control" id="contact" placeholder="Enter your Contact number" name="contact">
    </div>
  <div class="mb-3">
      <label for="email">Email</label>
      <input type="email" class="form-control" id="email" placeholder="Enter your email address" name="email">
    </div>
  <div class="text-center">
    <button type="submit" name="submit" class="btn btn-primary">Submit</button>
  </div>
  </form>
</div>
</div>

</body>
<?php 
$msg="";
$css_class="";
if(isset($_POST["submit"])){
  if(mysqli_query($db,"insert into registration(Enroll_id,Name,Course,Address,Mobile,Email,profileImage) values(NULL,'$_POST[name]','$_POST[course]','$_POST[address]','$_POST[contact]','$_POST[email]','$profileImagename')")){
    $msg="User saved to database";
    $css_class="alert-success";
  }else{
    $msg="failed to save data to the database";
    $css_class="alert-danger";
  }}
?> 
<script type="text/javascript">
 window.location.href=window.location.href;
</script>

<?php 
}
?>
</html>