How to Send Submissions to Your MySQL Database Using PHP

September 2, 2024

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.

Youtube Embed Poster: _Ua-thPgkBI

To save submissions to your database

  1. Create your database and table.
    The columns in your table will depend on your form’s structure. See this guide to view 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, ensure to add a “submission_id” column in your table.
    In this example form, the table looks as follows in phpMyAdmin:
A table in phpMyAdmin

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.
A database information declaration in PHP
  1. Next, search for Data to Save and add the POST data to save in your database.
POST data to variable assignments in PHP

Use the real_escape_string() function to prevent possible SQL injection vulnerabilities. To check your form’s POST data, see How to View Submissions as POST Data.

  1. Search for Queries to Run and edit the UPDATE query. Map the post values to your table columns. For more information, see MySQL UPDATE Statement.
A MySQL UPDATE statement in PHP
  1. Do the same with the INSERT query. For more information, see MySQL INSERT Statement.
A MySQL INSERT statement in PHP
  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. See Sending Submission Data via a POST Request for more information.
  3. Send a test entry to your form and confirm the results.
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:

  • GEORGE KAMAU - Profile picture
  • Ngobya - Profile picture
  • Jaime Isaac Bojorquez Guerrero - Profile picture
  • Villan Johain - Profile picture
  • Bright - Profile picture
  • Suesue - Profile picture
  • Livingstonpars tracker - Profile picture
  • maryam ghaderi - Profile picture
  • eaeong - Profile picture
  • alievserega17 - Profile picture
  • jotbeginner - Profile picture
  • ce4atomizer - Profile picture
  • ce4atomizer - Profile picture
  • Farras Naufal - Profile picture
  • skenney - Profile picture
  • aniket - Profile picture
  • eljay - Profile picture
  • eljay - Profile picture
  • Ravindra - Profile picture
  • Patricia Thuli - Profile picture
  • tdp4events - Profile picture
  • lplatz - Profile picture
  • adel - Profile picture
  • hammersoftware - Profile picture
  • ampsys - Profile picture