Skip to content
doubtly

2 answers

Create the form in HTML and send its data to a server-side script (for example PHP) that inserts it into a MySQL table.

1. Table in MySQL

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(50), email VARCHAR(100),
  password VARCHAR(255)
);

2. HTML form (register.html)

<form action="register.php" method="post">
  Name: <input type="text" name="name" required><br>
  Email: <input type="email" name="email" required><br>
  Password: <input type="password" name="password" required><br>
  <input type="submit" value="Register">
</form>

3. PHP script (register.php)

<?php
$conn = new mysqli("localhost", "root", "", "mydb");
if ($conn->connect_error) die("Connection failed");
$hash = password_hash($_POST["password"], PASSWORD_DEFAULT);
$stmt = $conn->prepare(
  "INSERT INTO users (name, email, password) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $_POST["name"], $_POST["email"], $hash);
echo $stmt->execute() ? "Registered successfully" : "Error";
$conn->close();
?>

HTML alone cannot talk to a database. The form's action sends the data by POST to register.php, which connects to MySQL and stores it. The prepared statement prevents SQL injection, and password_hash() stores the password safely. Run it on a server such as XAMPP/WAMP.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.