Here is a basic example of a Register system using PHP and HTML:
This HTML code creates a basic form with three input fields: name, email, and password. The form’s action is set to “register.php”, which means that when the form is submitted, the data will be sent to the “register.php” file for processing.
Table of Contents
Register system using PHP and HTML Example:
File Name: Registration.php
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h1>Registration Form</h1>
<form action="register.php" method="post">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name"><br>
<label for="email">Email:</label><br>
<input type="text" id="email" name="email"><br>
<label for="password">Password:</label><br>
<input type="password" id="password" name="password"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
File Name: register.php
This PHP register code gets the form data from the POST request and stores it in variables. It then validates the form data to make sure that all fields have been filled in. If any of the fields are empty, the script dies with an error message.
Next, the script connects to a MySQL database and inserts the new user into the “users” table. If the insertion is successful, it displays a success message. Otherwise, it displays an error message.
<?php
// Get the form data
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
// Validate the form data
if (empty($name) || empty($email) || empty($password)) {
die("Please fill in all fields");
}
// Connect to the database
$db = mysqli_connect("localhost", "my_user", "my_password", "my_database");
// Check the connection
if (!$db) {
die("Connection failed: " . mysqli_connect_error());
}
// Insert the new user into the database
$sql = "INSERT INTO users (name, email, password) VALUES ('$name', '$email', '$password')";
if (mysqli_query($db, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($db);
}
// Close the connection
mysqli_close($db);
?>
Read More.
- The Ultimate Guide to the Top 10 Java Frameworks for 2024.
- A Comprehensive Guide to Using javascript:location.reload(true) in Web Development
- PHP explode Multiple Separators: A Comprehensive Guide.
- Copy Constructor in Java: A Complete Guide
- 50 Ultimate PHP Project Topics to Elevate Your Development Skills.