How to Send Submissions to Your MySQL Database Using PHP

January 3, 2023

This guide shows how to send and save form data to a MySQL database after submission using PHP. A basic understanding of MySQL and PHP is required.

Let’s get started:

  1. Create your database and table.
    The columns in your table will depend on your form’s structure. Check out this guide to see your form’s field names or post keys if you’re not sure what columns to add to your database table.
  2. For this guide, make sure to add the column “submission_id” in your table.
    In this sample contact form, the table looks like the following in phpMyAdmin:
phpmyadmin-your-database-table-min.png

Note: The process for creating or editing your database will depend on your server setup or web host. Reach out to your provider’s support for assistance.

  1. Now, download and extract this ZIP file containing the code.
  2. Open the PHP file in your text editor.
  3. Search for Database Config in the code and replace the values with your database information.
php-database-config-min.png
  1. Next, search for Data to Save and add the POST data to save in your database.
php-data-to-save-min.png

Use the real_escape_string() function to prevent possible SQL injection vulnerabilities.

  1. Search for Queries to Run and edit the UPDATE query.
php-update-query-min.png

Map the post values to your table columns. For more information, see MySQL UPDATE Statement.

  1. Do the same with the INSERT query.
php-insert-query-min.png

For more information, see MySQL INSERT Statement.

  1. Save the PHP file and upload it to your server — take note of the file’s URL.
  2. Now, set up your form to send data to your PHP file’s URL.
    For more information, see Sending Submission Data via a POST Request.
  3. Send a test entry to your form and confirm the results.
Was this guide helpful?
Contact Support:

Our customer support team is available 24/7 and our average response time is between one to two hours.
Our team can be contacted via:

Support Forum: https://www.jotform.com/answers/

Contact Jotform Support: https://www.jotform.com/contact/

Send Comment:

Jotform Avatar
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Comments: