Home >> PHP MySql >> How to Create Register Form with Validation in PHP MySql

How to Create Register Form with Validation in PHP MySql

1)-Create Database
http://localhost/phpmyadmin
Database Name: education
MySQL Query
CREATE DATABASE education;  
2)-Create Table
Table Name: users
MySQL Query
CREATE TABLE IF NOT EXISTS `users` (  
  `user_id` int (11) NOT NULL,
  `username` varchar(200) NOT NULL,  
  `password` varchar(200) NOT NULL,  
  PRIMARY KEY (`user_id`)  
) ENGINE=InnoDB DEFAULT CHARSET=latin1;   
3)-Default folder is c:/xampp/htdocs.
 
4)-Create register.php in folder c:/xampp/htdocs.
<?php  
 //database connection
 $conn=mysqli_connect("localhost","root","","education");
 if(isset($_POST["submit"])){  
    if(!empty($_POST['user']) && !empty($_POST['pass'])) {  
        $user=$_POST['user'];  
        $pass=$_POST['pass'];  
        $query=mysqli_query($conn,"INSERT INTO users(username, password)values('".$user."', '".$pass."')");   
        if($query>0) {  
            session_start();  
            $_SESSION['sess_user']=$user;  
            header("Location: myprofile.php"); 
        } else {  
    echo "Invalid username or password!";  
        }  
    } else {  
       echo "All fields are required!";  
    }  
}  
?>  
<!doctype html>  
<html>  
<head>  
<title>Register Form</title>   
</head>  
<body>  
<h3>Register Form</h3>  
<form action="" method="POST">  
    Username: <input type="text" name="user"><br />  
    Password: <input type="password" name="pass"><br />   
    <input type="submit" value="Register" name="submit" />  
</form>  
</body>  
</html> 

Post Your Comment

Next Questions
How to Create Login Form with Remember
How to Change Login Password
How to Display User Profile after Login
How to Display User Data after Login
How to Display User Information after Login

Copyright ©2022 coderraj.com. All Rights Reserved.