MySQL Database Connection & Login System

    Posted On : 2021-05-19 17:03:25 PM


We have mentioned the MySQL database Connection and create a login system for the website.

The majority of websites allow the user to sign up and login. The user must generate a password and use it to access the website. However, it is important to protect the user's password. The password_hash() function allows you to safely store the user's password in the database.

First Create a db.php File and Place below Code:

  $db_host = "localhost";
  $db_name = "DB_NAME";
  $db_pass = "";
  $db_user = "root";
  $conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name);
  if (!$conn){
    die ('Failed to connect with server');

Second Create File signup.php and paste the following code into:

  //Include database connection file
  include 'db.php';
  if (isset($_POST['submit'])){
    $username = $_POST['username'];
    // Normal Password
    $pass = $_POST['password']; 
    // Securing password using password_hash
    $secure_pass = password_hash($pass, PASSWORD_BCRYPT);
    $sql = "INSERT INTO login_tb (u_username, u_password)
    VALUES('$username', '$secure_pass')";
    $result = mysqli_query($conn, $sql);

<form action="signup.php" method="POST">
  <label for="username">Username</label>
  <input type="text" name="username" required><br><br>
  <label for="password">Password</label>
  <input type="password" name="password" required><br><br>
  <input type="submit" name="submit" value="submit">    


Quick Contact !

Ask Question ?

Call Our Customer Care Executive. We Are Available 24x7 Just Dial.

+91 9810833751

Home | Contact | Sitemap © All Copyright 2021 Reserved