April 29, 2015

How to Insert Form Data Into a MySQL Database Using PHP

Why won’t my form data insert properly into my MySQL database? Here’s the most common reasons why:

Get the updated source code for this video here.

The two most common issues I see developers having are:

  1. Not connecting to MySQL properly
  2. Not matching form fields to database columns properly

Issues Connecting to MySQL

When you run into connection issues, you’ll usually see an error that will say there was a problem connecting to the database.

More often than not, it’s simply a typo in your database name, username, or password.

Make sure to triple-check that information. Also, keep in mind if you’re using source code I’ve provide you’ll need to change those values to whatever they are for YOUR database.

Issues Matching Form Fields to Database Columns

Almost always, this is caused by a mis-match between your form field names and your database column names.

In your SQL statement, you do the matching directly. Here’s a quick example:

INSERT INTO table_name (database_column_1, database_column_2) VALUES (form_field_1, form_field_2)

So you need to match the form field value to the database column.

I go much more in-depth with this in the video, so be sure to watch it if you’re having this problem.

If you enjoyed this tutorial and want to keep learning PHP, you can start taking my full course for free on my free tutorial site here:

6 Comments on “How to Insert Form Data Into a MySQL Database Using PHP

April 29, 2018 at 3:01 am


by Carros

August 7, 2018 at 8:28 am

Very good information. Thanks…

John Morris
August 7, 2018 at 8:57 am


January 22, 2019 at 1:16 pm

I like the way you explain. very clearly thank you

John Morris
January 22, 2019 at 5:39 pm

No problem!

VIvek Raj
April 17, 2019 at 7:15 am

Great, Thanks for sharing.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.