How to Insert Form Data Into a MySQL Database Using PHP

DISCLAIMER: This post may contain “affiliate” links to products and services I recommend. I’ll receive a small commission if you decide to purchase one of these products or services. I only recommend products I genuinely believe will help you in running your freelance business.

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.

  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: https://johnsfreetuts.com/php/

You might also like

Do you want more freelance clients?

I’ll show you what I learned over the last 15 years to grind out (from absolute scratch) a backlog of new clients wanting to hire you. Who your best client prospect are, what services you should be offering them, where to find them and more. Just enter your email address in the box below and let’s get started:

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on reddit
Reddit
Share on pinterest
Pinterest
John Morris

JOHN MORRIS

I’m a 15-year veteran of freelance web development. I’ve worked with bestselling authors and average Joe’s next door. These days, I focus on helping other freelancers build their freelance business and their lifestyles.

This Post Has 7 Comments

  1. Very good information. Thanks…

  2. I like the way you explain. very clearly thank you

  3. Hey,
    Great, thanks for sharing us. really it’s very useful.

Leave a Reply

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

Do you want more freelance clients?

Enter your email below to get started building your system for consistently bringing in new freelance clients:

WHAT OTHERS ARE SAYING

Lori Grant

John did an outstanding job on my project. I highly recommend him and look forward to working with him on future projects.

Bradley Smith

John and I have worked together on numerous projects. John is very quick and efficient and was a pleasure to work with.

Chris Aitken

He significantly improved my site through his expert knowledge of PHP, CSS and Javascript. Would definitely recommend John to others.

Sukh Plaha

John is a fantastic and patient tutor, who is not just able to share knowledge and communicate it very effectively – but able to support one in applying it. However, I believe that John has a very rare ability to go further than just imparting knowledge and showing one how to apply it. He is able to innately provoke one’s curiosity when explaining and demonstrating concepts, to the extent that one can explore and unravel their own learning journey. Thanks very much John!

Thabo Motsoahae

John is one of the best instructors I have come across, I learned a lot from his online tutorials.

Ray Edwards

I recommend John every chance I get. If every person I worked with were as committed to excellence, punctuality, value, and unquestionable integrity… the world would be a better place. Highest recommendation.

Daniel Mohlendick

On the Freelancing on Upwork course: “This is by far the best course i have watched on Skillshare!! Thank you so much.”

Close Menu