🌐
W3Schools
w3schools.com › php › php_form_complete.asp
PHP Complete Form Example
Here is the complete code for the PHP Form Validation Example:
🌐
Cloudways
cloudways.com › home › learn php tutorials, tips and guides › how to create a php contact form with mysql, ajax, and captcha
How to Create PHP Contact Form With MySQL & HTML5 Validation
March 22, 2026 - Learn how to build a PHP contact form with MySQL, HTML5 validation, AJAX, and CAPTCHA. Code examples for the form, database, mail handler, and spam protection.
People also ask

How do I store PHP contact form submissions in MySQL?
Connect to MySQL using mysqli or PDO, sanitize the submitted values using real_escape_string() or prepared statements, then run an INSERT query to save the data to your submissions table. Retrieve stored submissions later using SELECT queries in phpMyAdmin or your admin panel.
🌐
cloudways.com
cloudways.com › home › learn php tutorials, tips and guides › how to create a php contact form with mysql, ajax, and captcha
How to Create PHP Contact Form With MySQL & HTML5 Validation
How do I create a PHP contact form?
Create an HTML form with POST method, write a PHP script to validate and process the submitted data using $_POST, insert the data into MySQL with sanitized values, and send an email notification using mail() or PHPMailer.
🌐
cloudways.com
cloudways.com › home › learn php tutorials, tips and guides › how to create a php contact form with mysql, ajax, and captcha
How to Create PHP Contact Form With MySQL & HTML5 Validation
Do I need PHP for a contact form?
PHP is the standard server-side language for processing contact form submissions, validating input, and sending email. Alternatives include JavaScript with a backend API or third-party form services, but PHP remains the most common choice for self-hosted solutions.
🌐
cloudways.com
cloudways.com › home › learn php tutorials, tips and guides › how to create a php contact form with mysql, ajax, and captcha
How to Create PHP Contact Form With MySQL & HTML5 Validation
🌐
W3Schools
w3schools.com › php › php_forms.asp
PHP Form Handling
The PHP superglobals $_GET and $_POST are used to collect form-data. The example below displays a simple HTML form with two input fields and a submit button:
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-insert-form-data-into-database-using-php
How to Insert Form Data into Database using PHP ? - GeeksforGeeks
July 23, 2025 - We can use either the GET or POST method to send data to the server. <form action=other_page.php method= POST/GET> Form Elements... </form> Note: In PHP, we can connect to the database using the localhost XAMPP web server.
🌐
Phpdatabaseform
phpdatabaseform.com
PHP Database Form
You can generate a web form with only 2 lines of code – Learn more · $dbForm = new C_DatabaseForm("SELECT * FROM employees", "EmployeeID", "employees"); $dbForm -> display(); Show the generated online form! Only TWO lines of PHP code required to generate form.
🌐
Sanwebe
sanwebe.com › html-css › php › snippets › creating simple form using php and mysql
Creating Simple Form using PHP and MySql – Sanwebe
July 1, 2025 - Unless you intentionally want to store HTML in the database (e.g., for a rich text editor), you should sanitize inputs to remove harmful content and validate them to ensure they meet your requirements. 12345678910111213141516171819202122232425262728293031323334 · &lt;?php // process.php if ($_SERVER["REQUEST_METHOD"] == "POST") { $u_name = filter_input(INPUT_POST, "user_name", FILTER_SANITIZE_SPECIAL_CHARS); $u_email = filter_input(INPUT_POST, "user_email", FILTER_SANITIZE_EMAIL); $u_text = filter_input(INPUT_POST, "user_text", FILTER_SANITIZE_SPECIAL_CHARS); $errors = []; if (empty($u_name))
🌐
DEV Community
dev.to › anthonys1760 › how-to-insert-form-data-into-a-database-using-html-php-2e8
How to Insert Form Data into a Database Using HTML & PHP - DEV Community
August 22, 2022 - Create a database name of SampleDB and a table name of SampleTable. Create our HTML and PHP files in our Code Editor. I am using Visual Studio Code. Submit our data through the form we created.
Find elsewhere
🌐
Phpdatabaseform
phpdatabaseform.com › examples
Examples | PHP Database Form
Build your first web form in two lines of PHP code. Below example generates the form from a database table named “employees”. When using star, it generates a web form with each form element ordered by database table column from the left most column to right most.
🌐
Jotform
jotform.com › user guides › advanced features › how to send submissions to your mysql database using php
How to Send Submissions to Your MySQL Database Using PHP
February 4, 2025 - Reach out to your provider’s support for assistance. Now, download and extract this ZIP file containing the code. Open the PHP file in your text editor. Search for Database Config in the code and replace the values with ...
🌐
Raghwendra
raghwendra.com › home › how to connect html to database with mysql using php? an example
How to connect HTML to database with MySQL using PHP? example
June 25, 2023 - You will get the complete form in HTML coding in step 3. Open a web browser (chrome, firefox, edge, etc., ) and type this http://localhost/phpmyadmin/ or http://127.0.0.1/phpmyadmin/ for open GUI for managing DB on your computer. See the xampp screen below how it is coming. Click on the databases link and create your db by the name “db_contact”. See the image below: After creating your DB you need to create a table by any name I choose “tbl_contact” with the number of field 5.
Top answer
1 of 2
3

There are a few things wrong here.

You're using the wrong identifiers for your columns in (and being quotes):

('id', 'username', 'password', 'email')

remove them

(id, username, password, email)

or use backticks

(`id`, `username`, `password`, `email`)

mysql_error() should have thrown you an error, but it didn't because of:

  • You're mixing MySQL APIs with mysqli_ to connect with, then mysql_ in your query.

Those two different APIs do not intermix with each other.

Use mysqli_ exclusively and change your present query to:

if($query = mysqli_query($connect, "INSERT...

and change mysql_error() to mysqli_error($connect)

as a rewrite for that block:

if(isset($_POST["submit"])){
    if($query = mysqli_query($connect,"INSERT INTO users ('id', 'username', 'password', 'email') VALUES('', '".$username."', '".$password."', '".$email."')")){
        echo "Success";
    }else{
        echo "Failure" . mysqli_error($connect);
    }
}

Just to test the error, make the changes as I outlined just above, while keeping the quotes around your columns the way you have it now. You will then see the error that MySQL will throw. You can then do as I've already outlined above and remove the quotes around the column names, or replace them with backticks.

The tutorial you saw may very well used backticks, but were probably not distinguishable enough for you to tell that they were indeed backticks and not single quotes.

However, your present code is open to SQL injection. Use mysqli with prepared statements, or PDO with prepared statements, they're much safer.


I noticed you may be storing passwords in plain text. If this is the case, it is highly discouraged.

I recommend you use CRYPT_BLOWFISH or PHP 5.5's password_hash() function. For PHP < 5.5 use the password_hash() compatibility pack.


Also, instead of doing:

$connect = mysqli_connect("localhost", "root", "") or die("Could not connect to server!");
mysqli_select_db($connect, "php_forum") or die("Could not connect to database!");

You should be checking for errors instead, just as the manual states

$link = mysqli_connect("myhost","myuser","mypassw","mybd") 
or die("Error " . mysqli_error($link)); 
  • http://php.net/manual/en/function.mysqli-connect.php

So in your case:

$connect = mysqli_connect("localhost", "root", "","php_forum") 
or die("Error " . mysqli_error($connect)); 

Edit: and I changed action="register.php" to action="" since you're using the entire code inside the same page.

<!DOCTYPE HTML>
<html>
    <head>
        <title>Register</title>
    </head>
    <body>
        <form action="" method="POST">
            Username: <input type="text" name="username">
            <br/>
            Password: <input type="password" name="password">
            <br/>
            Confirm Password: <input type="password" name="confirmPassword">
            <br/>
            Email: <input type="text" name="email">
            <br/>
            <input type="submit" name="submit" value="Register"> or <a href="login.php">Log in</a>
        </form>
    </body>
</html>
<?php
    require('connect.php');
    $username = $_POST['username'];
    $password = $_POST['password'];
    $confirmPassword = $_POST['confirmPassword'];
    $email = $_POST['email'];

    if(isset($_POST["submit"])){
        if($query = mysqli_query($connect,"INSERT INTO users (`id`, `username`, `password`, `email`) VALUES ('', '".$username."', '".$password."', '".$email."')")){
            echo "Success";
        }else{
            echo "Failure" . mysqli_error($connect);
        }
    }
?>
2 of 2
-1

:It will echo ;Failure' so executing this bit of code

 else{
            echo "Failure" . mysql_error();
        }

whenever $_POST["submit"]) is not set and it will be not set anytime you open you page (even if you navigate to it from your bookmark of from google search results) or when you submit you FORM in GET mode

🌐
PHPpot
phppot.com › php › php-login-form
PHP Login Form with MySQL Database (Complete Login System Example) - PHPpot
March 14, 2026 - Build a login form with email and password fields. Validate the form input. Query the database using prepared statements. Verify the password using password_verify(). Create a session after successful login. Redirect the user to a protected dashboard page. This tutorial demonstrates a simple PHP login system using MySQL. ... This example is beginner friendly and can run in any PHP hosting environment such as XAMPP or MAMP.
🌐
Medium
medium.com › @biswajitpanda973 › signup-form-using-php-and-mysql-database-c85496678463
Signup form using PHP and MySQL Database | by biswajit panda | Medium
June 21, 2024 - This form collects the user’s email, password, and a confirmation of the password. The form data is submitted to create_user.php via the POST method. This comparison highlights the key differences between the GET and POST methods : ... Next, we’ll create a connection.php file to handle the database connection.
🌐
PHP
pear.php.net › manual › en › package.database.db-table.intro-forms.php
Manual :: Creating HTML_QuickForm forms
If your column form element is 'checkbox', 'radio', or 'select', you can set the values of the available choices for the form element. You do so via an 'sq_vals' element in the corresponding column definition. ... For a checkbox, use a sequential array of two elements: the first is the value if the box is not checked, and the second is the value if it is checked. In this example, the checkbox values are 0 if not checked,and 1 if checked; these are the values that will be stored in the column.
🌐
Educative
educative.io › answers › how-to-connect-an-html-form-to-a-mysql-database-in-php
How to connect an HTML form to a MySQL database in PHP
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Contact Form</title> </head> <body> <h2>Contact Form</h2> <form action="form.php" method="post"> <label ...
🌐
Quora
quora.com › How-can-I-build-a-PHP-form-using-a-MySQL-database
How to build a PHP form using a MySQL database - Quora
Answer (1 of 2): Heres the code which i recently used to make form through php, mysql and html. Step 1: Make a simple HTML form as you wish to create as per your requirment. or heres my created form. Code is: [code]
🌐
Eli the Computer Guy
elithecomputerguy.com › 2019 › 12 › mysql-insert-records-with-html-form-and-php
MySQL – INSERT Records with HTML Form and PHP – Eli the Computer Guy
<html> <body> <form action="phpForm.php" method="post"> Name: <input type="text" name="name"><br> Age: <input type="text" name="age"><br> Gender: <select name="gender"> <option value=" "> </option> <option value="boy">Boy</option> <option value="girl">Girl</option> </select><br> <input type ="submit"> </form> </body> </html> phpTEST.php (Verify HTML Form and PHP are working)
🌐
IONOS
ionos.com › digital guide › websites › web development › use php to insert information into a mysql/mariadb database from an html form
Use PHP to Insert Information Into a MySQL/MariaDB Database From a HTML Form - IONOS
June 14, 2021 - This form uses the POST method to pass data to the addreview.php PHP script. The name for each input field will be used as the PHP variable name in the next step. It is usually best to use the database table field name for these values. Never trust user input. In this example, we require a ...
🌐
C# Corner
c-sharpcorner.com › UploadFile › 52bd60 › create-an-html-form-and-insert-data-into-database162
Create An HTML Form And Insert Data Into The Database Using PHP
November 20, 2023 - This article shows how we can create a SIGN UP form and store the entered data into our database (mysql) using PHP.
🌐
Medium
medium.com › @gihan2000v › save-html-form-data-to-a-mysql-database-using-php-3d48742a1451
Save HTML Form Data to a MySQL Database using PHP | by GihanVimukthi | Medium
February 10, 2023 - <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="newproject.css"> <title>New Project</title> </head> <body> <h3>EXAMPLE PROJECT</h3><br><br> <form action="process-exampleform.php"method="POST"> <div class="firstname"> <label>First_Name</label><br> <input type="text" id="Code" name="First_Name"> </div> <div class="lastname"> <label>Last_Name</label><br> <input type="text" id="Code" name="Last_Name"> </div> <button>Submit</button>