If you are visiting my channel for the first time then please subscribe
Go to my Youtube channel :
https://www.youtube.com
Here's an example of a simple signup form in PHP:
1. Create a new Html file called sineup.html with the following code:
<!DOCTYPE html>
<html>
<head>
<title>Signup Form</title>
</head>
<body>
<h1>Signup Form</h1>
<form action="signup.php" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"><br><br>
<label for="cpassword">Conform Password:</label>
<input type="password" id="cpassword" name="cpassword"><br><br>
<button type="submit" name="submit">Signup</button>
</form>
</body>
</html>
2. In this form, there are three input fields: name, email, and password. When the user submits the form, the data is sent to a PHP script called signup.php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// email and password sent from form
//The name of the database for CodeWithAr
define('DB_NAME', 'test');
//MySQL database User Name
define('DB_USER', 'root');
//MySQL database password
define('DB_PASSWORD', '');
//MySQL hostname
define('DB_HOST', 'localhost');
// Create connection
$conn = new mysqli(
DB_HOST, // Databes Host
DB_USER, // Databes User Name
DB_PASSWORD, // Databes Password
DB_NAME // Databes Name
);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$confirm = mysqli_real_escape_string($conn, $_POST['confirm']);
$sql = "INSERT INTO `users` (`email`, `name`, `password`, `confirm`)
VALUES ('$email', '$name', '$password', '$confirm');";
if ($conn->query($sql) === TRUE) {
echo "Signup successful";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
This code first checks if the form was submitted (isset($_POST['submit'])), then it retrieves the form data using the $_POST superglobal array. It then validates the input data (which you should always do to prevent security vulnerabilities), and saves the data to a database. The example code uses MySQLi to connect to a MySQL database and insert the data into a users table. However, you can use a different database or file storage method depending on your requirements.
Disclaimer video is for educational purpose only. Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for "fair use" for purposes such as criticism, comment, news reporting, teaching, scholarship, and research. Fair use is a use permitted by copyright statute that might otherwise be infringing. Non-profit, educational or personal use tips the balance in favor of fair use .
Thanks..
Copyright © 2021-2023 | WsCoder | All Right Reserved