How to Send Submissions to Your MySQL Database Using PHP

February 24, 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:
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.
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.
A MySQL UPDATE statement in PHP

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

  1. Do the same with the INSERT query.
A MySQL INSERT statement in PHP

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.
END OF YEAR SALE
Save 50%
ON ANNUAL JOTFORM PLANS
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:

  • 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
  • Sarika - Profile picture
  • vivek raj - Profile picture
  • Mariana - Profile picture
  • bishopkldavis2 - Profile picture
  • تبلیغات گوگل - Profile picture
  • Chinakwadom - Profile picture
  • PRAJESH YEOTIKAR - Profile picture
  • Vanishree - Profile picture
  • shubham - Profile picture
  • Bjorn - Profile picture
  • manjeet - Profile picture
  • twarren42 - Profile picture
  • john - Profile picture
  • mshafiq1 - Profile picture
  • test - Profile picture
  • mario - Profile picture
  • vivek raj - Profile picture
  • puneet - Profile picture
  • Php On Web - Profile picture
  • Rob - Profile picture
  • Morris - Profile picture
  • chris - Profile picture
  • Gede Adi - Profile picture
  • vaishshagun - Profile picture
  • Itunes customer service - Profile picture
  • HNUSK - Profile picture
  • lalithsagar - Profile picture
  • Modestus - Profile picture
  • Xprobes - Profile picture
  • Chitti - Profile picture
  • nani - Profile picture
  • Imran - Profile picture
  • Akash Aher - Profile picture
  • Jan Hovens - Profile picture
  • karthik - Profile picture
  • javeriamahveen - Profile picture
  • hhaaee - Profile picture
  • omkar - Profile picture
  • anam - Profile picture
  • saima - Profile picture
  • Hamza Y.A - Profile picture
  • Nafiu gide - Profile picture
  • mobotak  - Profile picture
  • rafay Tariq - Profile picture
  • valuchi - Profile picture
  • Mugisha isaac - Profile picture
  • Hery - Profile picture
  • Alemayehu Waza - Profile picture
  • Surendra Bharadwaj - Profile picture
  • ifin2000 - Profile picture
  • shiprequest - Profile picture
  • Hannah - Profile picture
  • Rick - Profile picture
  • Francis - Profile picture
  • AirGermanWolf - Profile picture
  • tort - Profile picture
  •  - Profile picture
  • Abhinav - Profile picture
  • pktfteam - Profile picture
  • tochi - Profile picture
  • Abdulrasheed - Profile picture
  • charie - Profile picture
  • paul - Profile picture
  • GSPNetworks - Profile picture
  • lalunavariete - Profile picture
  • Michael - Profile picture
  • syucom - Profile picture
  • Donna - Profile picture
  • chrisediting - Profile picture
  • donnashanks - Profile picture
  • kokyi - Profile picture
  • aquades - Profile picture
  • 2sweetdesignstudio - Profile picture
  • EltonCris - Profile picture
  • lukesbfi - Profile picture
  • TitusN - Profile picture
  • RCinSTP - Profile picture
  • harry - Profile picture
  • jamesforpm - Profile picture
  • RAccessPro - Profile picture
  • jamesforpm - Profile picture
  • RAccessPro - Profile picture
  • jamesforpm - Profile picture
  • dalepotter_upreach - Profile picture
  • Akabuo - Profile picture
  • texico - Profile picture
  • tunji - Profile picture
  • donadioj - Profile picture
  • dgkg - Profile picture
  • Antonio - Profile picture
  • sportsaac - Profile picture
  • selin - Profile picture
  • Iwan Saputa - Profile picture
  • embscareers - Profile picture
  • Xavier - Profile picture
  • Dir3t - Profile picture
  • sujeet - Profile picture
  • yuyun - Profile picture
  • yuyun - Profile picture
  • amit kumar  - Profile picture
  • estvmachine - Profile picture
  • Nyameko Yabo - Profile picture
  • jacknab - Profile picture
  • guest_22721662966056 - Profile picture
  • infoges - Profile picture
  • rexjimtw - Profile picture
  • grassmedia - Profile picture
  • foodorders - Profile picture
  • Alexx123 - Profile picture
  • bappy - Profile picture
  • gappsmasters - Profile picture
  • schef - Profile picture