- Login and Registration Form in PHP + MySQL using XAMPP
- Login and Registration Form in PHP and MySQL using XAMPP
- Step 1 – Open the XAMPP Control Panel & Create PHP Project
- Step 2 – Create Database and Table
- Step 3 – Create a Database Connection File
- Step 4 – Create registration form and Insert data into MySQL database
- Step 5 – Create Login Form In PHP with MySQL
- Step 6 – Create User Profile and Fetch data From Database
- Step 7 – Create Logout.php file
- Conclusion
- Форма регистрации на PHP с использованием базы данных MySQL
- Подключаемся к БД
- Создаем форму регистрации
- Смотрим результат
- Create Registration form with MySQL and PHP
- Contents
- 1. Table structure
- 2. Configuration
- 4. Form Submit
- 5. Demo
- 6. Conclusion
- PHP: Форма входа и регистрации в PHP + MySQL
- Шаг 1 — Откройте панель управления сервера и создайте проект PHP
- Шаг 2 — Создайте базу данных и таблицу
- Шаг 3 — Создайте файл подключения к базе данных
- Шаг 4 — Создайте регистрационную форму и вставьте данные в базу данных MySQL
- Шаг 5 — Создайте форму входа в PHP с MySQL
- Шаг 6 — Создайте профиль пользователя и получите данные из базы данных
- Шаг 7 — Создайте файл Logout.php
Login and Registration Form in PHP + MySQL using XAMPP
Simple login and registration form in PHP + MySQL + Boostrap using xampp. In this tutorial; you will learn how to create a simple login and registration form in PHP and MySQL using xampp with source code.
You can also download the complete source code of simple login and registration form in PHP + MYsql + Bootstrap using xampp from github.
Login and Registration Form in PHP and MySQL using XAMPP
- Step 1 – Open the XAMPP Control Panel & Create PHP Project
- Step 2 – Create Database and Table
- Step 3 – Create a Database Connection File
- Step 4 – Create a registration form and Insert data into MySQL database
- Step 5 – Create Login Form in PHP with MySQL
- Step 6 – Create User Profile and Fetch Data From MySQL Database
- Step 7 – Create Logout.php file
Step 1 – Open the XAMPP Control Panel & Create PHP Project
Visit your xampp installed directory. Then open xampp control panel and start it; then visit xampp/htdocs directory. And inside this directory create php project directory.
Step 2 – Create Database and Table
Create a database name my_db and execute the below-given query in your database. The below query will create a table named users in your database with the following fields like uid, name, email, mobile:
CREATE DATABASE my_db; CREATE TABLE `users` ( `uid` bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` varchar(255) DEFAULT NULL, `email` varchar(255) DEFAULT NULL, `mobile` varchar(255) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Step 3 – Create a Database Connection File
Create a file name db.php and update the below code into your file.
The below code is used to create a MySQL database connection in PHP. When you insert form data into MySQL database, there you will include this file:
Step 4 – Create registration form and Insert data into MySQL database
Create registration form file; which name registration.php. And add the following code into it:
if (isset($_POST['signup'])) < $name = mysqli_real_escape_string($conn, $_POST['name']); $email = mysqli_real_escape_string($conn, $_POST['email']); $mobile = mysqli_real_escape_string($conn, $_POST['mobile']); $password = mysqli_real_escape_string($conn, $_POST['password']); $cpassword = mysqli_real_escape_string($conn, $_POST['cpassword']); if (!preg_match("/^[a-zA-Z ]+$/",$name)) < $name_error = "Name must contain only alphabets and space"; >if(!filter_var($email,FILTER_VALIDATE_EMAIL)) < $email_error = "Please Enter Valid Email ID"; >if(strlen($password) < 6) < $password_error = "Password must be minimum of 6 characters"; >if(strlen($mobile) < 10) < $mobile_error = "Mobile number must be minimum of 10 characters"; >if($password != $cpassword) < $cpassword_error = "Password and Confirm Password doesn't match"; >if(mysqli_query($conn, "INSERT INTO users(name, email, mobile_number ,password) VALUES('" . $name . "', '" . $email . "', '" . $mobile . "', '" . md5($password) . "')")) < header("location: login.php"); exit(); >else < echo "Error: " : "" . mysqli_error($conn); >mysqli_close($conn); > ?>Please fill all fields in the form
Step 5 – Create Login Form In PHP with MySQL
Create login form, where you accept user email id and password and authenticate users from database. So you can create a login.php file and add the below code into your file:
if (isset($_POST['login'])) < $email = mysqli_real_escape_string($conn, $_POST['email']); $password = mysqli_real_escape_string($conn, $_POST['password']); if(!filter_var($email,FILTER_VALIDATE_EMAIL)) < $email_error = "Please Enter Valid Email ID"; >if(strlen($password) < 6) < $password_error = "Password must be minimum of 6 characters"; >$result = mysqli_query($conn, "SELECT * FROM users WHERE email = '" . $email. "' and pass = '" . md5($password). "'"); if(!empty($result)) < if ($row = mysqli_fetch_array($result)) < $_SESSION['user_id'] = $row['uid']; $_SESSION['user_name'] = $row['name']; $_SESSION['user_email'] = $row['email']; $_SESSION['user_mobile'] = $row['mobile']; header("Location: dashboard.php"); >>else < $error_message = "Incorrect Email or Password. "; >> ?>Please fill all fields in the form