You can find the POST data in PHP's $_POST variable. It should hold all the values that were passed via the POST method.

$name = $_POST["name"];

Answer from aplewandowski on Stack Overflow
๐ŸŒ
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:
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_form_complete.asp
PHP Complete Form Example
To show the values in the input fields after the user hits the submit button, we add a little PHP script inside the value attribute of the following input fields: name, email, and website. In the comment textarea field, we put the script between the <textarea> and </textarea> tags.
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_form_required.asp
PHP Forms Required Fields
Then in the HTML form, we add a little script after each required field, which generates the correct error message if needed (that is if the user tries to submit the form without filling out the required fields): <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> Name: <input type="text" name="name"> <span class="error">* <?php echo $nameErr;?></span> <br><br> E-mail: <input type="text" name="email"> <span class="error">* <?php echo $emailErr;?></span> <br><br> Website: <input type="text" name="website"> <span class="error"><?php echo $websiteErr;?></span> <br><
๐ŸŒ
W3Schools
w3schools.in โ€บ mysql โ€บ php-mysql-insert
How to Use the MySQL INSERT INTO Statement - W3Schools
<?php // Database connection establishment $con=mysqli_connect("hostname","username","password","db_name"); // Check connection if (mysqli_connect_errno($con)) { echo "MySQL database connection failed: " . mysqli_connect_error(); } // Insert mysqli_query($con,"INSERT INTO contact (name, email, message) VALUES ('Pavitra', '[email protected]', 'Test message')") ?> Collect user data seamlessly with HTML forms, as demonstrated below: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Contact Form</title> </head> <body> <form action="submit.php" method="post"> <fieldset> <div> <l
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_mysql_insert.asp
PHP MySQL Insert Data
PHP Form Handling PHP Form Validation PHP Form Required PHP Form URL/E-mail PHP Form Complete
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to Insert Form Data into Database using PHP - YouTube
In this video, we will store data in a database submitted through HTML form. Requirements:XAMPP Server (Web Server)HTMLPHPMySQL
Published ย  February 21, 2023
๐ŸŒ
W3Schools
w3schools.sinsixx.com โ€บ php โ€บ php_forms.asp.htm
PHP Forms - SinSiXX - W3Schools
Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_form_validation.asp
PHP Form Validation
These pages will show how to process PHP forms with security in mind. Proper validation of form data is important to protect your form from hackers and spammers! The HTML form we will be working at in these chapters, contains various input fields: required and optional text fields, radio buttons, and a submit button:
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_superglobals_post.asp
PHP $_POST Superglobal
PHP superglobals are built-in variables that are always accessible in all scopes! An HTML form submits data via the HTTP POST method if the form's method attribute is set to "post".
๐ŸŒ
W3Schools
w3schools.in โ€บ php โ€บ web-form
Building a Simple PHP Web Form - W3Schools
PHP is a good choice as it can manage form data securely and efficiently. Creating a web form involves designing an intuitive user interface and setting up a server-side script to handle the data securely: Creating the form's HTML structure involves designing a user-friendly layout and specifying the form fields: <form action="submit.php" method="POST"> <fieldset> <legend>Personal Information</legend> <label for="name">Name:</label> <input type="text" id="name" name="name" required> <label for="email">Email:</label> <input type="email" id="email" name="email" required> <input type="submit" value="Submit"> </fieldset> </form>
๐ŸŒ
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.
๐ŸŒ
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 - Storing User Input into a MySQL database using PHP is a foundational step in developing dynamic and data-driven web applications. Use HTML <form> elements to collect user data and submit it to PHP for processing.
๐ŸŒ
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 - Open the PHP file in your text editor. Search for Database Config in the code and replace the values with your database information. Next, search for Data to Save and add the POST data to save in your database.
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

๐ŸŒ
Medium
medium.com โ€บ write-a-catalyst โ€บ how-to-send-form-data-to-database-and-validate-with-php-0ed8e85d9914
How to Send Form Data to Database and Validate with PHP | by Yunus Emre Adas | Write A Catalyst | Medium
September 28, 2024 - In this tutorial, you would be taken through the steps involved in validating form data using PHP and submitting it safely to your database.
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ tutorial.forms.php
PHP: Dealing with Forms - Manual
The basic concept that is important to understand is that any form element will automatically be available to your PHP scripts. Please read the manual section on Variables from external sources for more information and examples on using forms with PHP. Here is an example HTML form: ... <form action="action.php" method="post"> <label for="name">Your name:</label> <input name="name" id="name" type="text"> <label for="age">Your age:</label> <input name="age" id="age" type="number"> <button type="submit">Submit</button> </form>
๐ŸŒ
W3Schools
w3schoolsua.github.io โ€บ php โ€บ php_form_complete_en.html
PHP Forms - Complete Form Example. Lessons for beginners. W3Schools in English
To show the values in the input fields after the user hits the submit button, we add a little PHP script inside the value attribute of the following input fields: name, email, and website. In the comment textarea field, we put the script between the <textarea> and </textarea> tags.
๐ŸŒ
Delft Stack
delftstack.com โ€บ home โ€บ howto โ€บ php โ€บ insert form data in a mysql database table in php
How to Insert Form Data Using MySQL Table in PHP | Delft Stack
February 2, 2024 - We have a table called parkinglot1 in our database sample tutorial. Below is what the table looks like: Letโ€™s assume we have a new entry to add to the table. Our new entry will be as follows, Ferrari for BrandName, Alex for OwnersName and, KJG564R for RegistrationNumber. How do we approach this? The first is to create an HTML form to collect the new data. We will have three slots to input data and a submit button in our HTML form. We do not need to include a CarID slot as PHP automatically updates the entry.
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_mysql_connect.asp
PHP MySQL Connect to database
PHP Form Handling PHP Form Validation PHP Form Required PHP Form URL/E-mail PHP Form Complete