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:
- 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. - 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:

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.
- Now, download and extract this ZIP file containing the code.
- Open the PHP file in your text editor.
- Search for Database Config in the code and replace the values with your database information.

- Next, search for Data to Save and add the POST data to save in your database.

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.
- 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.
- Do the same with the INSERT query.

For more information, see MySQL INSERT Statement.
- Save the PHP file and upload it to your server — take note of the file’s URL.
- 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. - Send a test entry to your form and confirm the results.
Send Comment:
135 Comments:
Hello,
Can we send post and also direct users to thank you page? Why disable thank you page? is it just to show the post message?
php script cant find?
I have done everything right by following a YouTube video, I was taught how to create a form and send it to a data base(XAMPP). the video coding worked but my coding has not work. after completion of the job. when i click on create account, the information are not save but it returned the php code back to me. And the information are not found in the database.
Hello. I can successfully insert submission data in my mysql table using mysqli. However, I cannot update data in my table when I edit submissions. Can anyone help me?
I have a database with the column names as id(Auto Increament), name and address.
i want the query that it can update or insert using the same button.
https:/www.jotformcom/form/90867582341161
I have created my form and my database. now I don't know where is the form php script.?
should I create it? or it is already exists?
If I should create it, where should I do that? in what platform?
Thank you
Thanks! I will do it soon!
Start XAMPP Server.
Open localhost/phpmyadmin in your web browser.
Create database of name staff and table of name college.
Write HTML and PHP code in your Notepad in a particular folder.
Submit data through HTML Form.
Verify the results.
@ce4atomizer
The mysql_connect() function was removed in PHP7. Use the mysqli_connect() function instead. Docs:
now the only problem is http 500 and
Stack trace:
#0 {main}
thrown in /home/topwax/public_html/index.php on line 25
[11-May-2021 07:11:46 UTC] PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/topwax/public_html/index.php:25
Stack trace:
#0 {main}
thrown in /home/topwax/public_html/index.php on line 25
this is the line 25: mysql_connect( $db_host, $db_username, $db_password) or die(mysql_error());
Hello, It's saying PHP Parse error: syntax error, unexpected 'arrays' (T_STRING) in /home/topwax/public_html/index.php on line 4 and http 500 error, please help
Hello. I got some trouble in the integration Jotform Submission to MySQL, i'm using php 7 but the complete script in tutorial "How to send Submissions to Your MySQL Database Using PHP" is doesn't work for me ):
Please help me to fix it, here is my script code :
Hi, This is exactly what I've been looking for .... my problem is that I am not a programmer, just a novice with a little project that I import 25 entries quarterly in my database. It sure would be much better to have it update with each submission rather imported all at once... And apparently since I have PHP version: 7.3.6 , some of the code must be updated, especially related to mysql to mysqli , and some others... Has this already been done somewhere ? If not I haven't been able to find it ... or could someone do it for me. Thanks in Advance, Steve
I have a database with the column names as id(Auto Increament), name and address.
i want the query that it can update or insert using the same button.
it also has a search button, but i am not able to search it. could you please help me
thank you
I am unable to figure out how to enter data into a form and then query mysql with the form entries and output the results:
e.g.
table_name=work
columns include but are not limited to labor, day, hours, etc.
form includes entry for 1. Drivers: trucks, cars, fork lifts; 2. Days: mon, tues, wed... ; Hours: day, afternoons, nights.
If I make entries into the form 1. trucks, 2: wed, 3: day then my query resembles SELECT * FROM work WHERE drivers = trucks AND days = mon AND hours = days then I want to enter the form data into a mysqli query and output which drivers drove a truck on the day shift on Monday.
Been pulling my hair out trying to get this to work.
I am unable to figure out how to enter data into a form and then query mysql with the form entries and output the results:
e.g.
table_name=work
columns include but are not limited to labor, day, hours, etc.
form includes entry for 1. Drivers: trucks, cars, fork lifts; 2. Days: mon, tues, wed... ; Hours: day, afternoons, nights.
If I make entries into the form 1. trucks, 2: wed, 3: day then my query resembles SELECT * FROM work WHERE drivers = trucks AND days = mon AND hours = days then I want to enter the form data into a mysqli query and output which drivers drove a truck on the day shift on Monday.
Been pulling my hair out trying to get this to work.
how to insert user IP address in table database?
Ii wanna know if im registered on the Data base
so how i can insert data ?
Can this script be modified to post form data into more than one table?
Thank you! this was great and helped me finish my marketing project on time. Appreciate all the awesome examples!.
Regards,
Just thought I'd mention, you're giving bad advice on how to solve SQL injection. Adding slashes is not going to work properly if the person is not using MySQL, which is why the php documentation for addslashes() specifically states that is bad advice and suggests that you use a database-specific method to solve it.
Instead a proper suggestion to tell the person wanting to save your data is to use prepared statements:
If you're using PHP, this can be accomplished via PDO or PEAR, or for MySQL specifically, you can use mysqli.
Using backslashes in SQL code can introduce a whole host of other problems.
From the same stackoverflow article:
For example, there(1) are(2) still(3) many(4) answers(5), including the second most upvoted answer suggesting you manual string escaping - an outdated approach that is proven to be insecure.
How do you get the array to include ALL data fields even when the form is set to skip/hide fields based on certain responses?
The problem I'm having is that I want the form to be interactive, but the results feed keeps changing. Sometimes it doesn't include fields altogether, other times it does but with a NULL value (which is fine), and yet other times still, the order is all jumbled up.
Obviously this causes the sql insert to fail because of mismatched data types or missing values altogether.
Please help!
Thanks.
How did you generete the form id and submission id in above program. I want to do the same in my project.
So please guide about this so that i can use that id for updating the information by user.
Hey,
Great, thanks for sharing us. really it's very useful.
test experience
WHEN SUBMITTING FORM USER SELECT AMOUNT OF $75.00 WHICH PAYPAL ACCEPTS WITH NO PROBLEMS. AMOUNT IS ENTER INTO PAYPAL, BUT NOT THE DATABASE. ALL THE FIELDS ARE ENTERED INTO THE DATABASE WITH THE EXCEPTION OF (registrationFee).
URL: <a target='_blank' href="https://www.jotform.com/build/90867582341161" >https://www.jotform.com/build/90867582341161</a>
mysql_query("INSERT INTO `registration` (submission_id, formID, ip, studentname, birthdate24, gender, address, studentemail6, mobilenumber, phonenumber25, degreetype, dateregistration, registrationFee)
VALUES ('" . $submissionData["submission_id"] . "',
'" . $submissionData["formID"] . "',
'" . $submissionData["ip"] . "',
'" . $studentname . "',
'" . $birthdate24 . "',
'" . $submissionData["gender"] . "',
'" . $submissionData["address"] . "',
'" . $submissionData["studentemail6"] . "',
'" . $mobilenumber . "',
'" . $phonenumber25 . "',
'" . $submissionData["degreetype"] . "',
'" . $dateregistration . "',
'" . $submissionData["registrationFee"] . "' ) ") or die(mysql_error());
very thanks, how i can do this with Ajax?
Send me more updates
Can i create an online customer entry database and when customer enters his/her name then the message should be automatically sent to him/her
Good example to understand
This will not work for PHP
Hi!
This will not work for PHP 7.0
hello world!
Thanks for the excellent example of posting form data to a database.
This is working!
great nice script
thanks for the script
Obligatory warning: `ExtendedAddslash()` is poor advise and will NOT prevent SQL injections. addslashes itself is insufficient to account for charset variations. See also:
Great, Thanks For Sharing.
good but worst
Hi dude, i have also find out one good example
Variables – Php Example
Really nice tutorial thank you
Thanks
thank you
Hai, can I have a php code submit data without using tag form ? so like if I click specified button so some data will send to data base (CRUD)
BEst Regards
i had a query that where we initalize our array??
This program has some bugs when the attached the date be to send the MySQL query to show you the error.
Hi,
I am new to PHP, Please help me ...
I need to display each student details from database into html form one by one on clicking next button using php.
i am new to php actually i have a question. i created a form and oce i submit the form data has to save in my database but data is not saving.can anyone help me with that.
div {
background-color: lightgrey;
width: 300px;
border: 25px solid green;
padding: 25px;
margin: 25px;
}
Hello Chatmate! Can you please assist me with PHP and SQL codes.
I wannah develop an ITs where i will need to use a form to entering Data in a SQL.
Best regards
i wonder, i have created a custom post type form for email submission. I was thinking that do they also get saved in any of my wp directory also. The forms are submitted to external post type to external url. Is there any trace submitted email left?
Very usefull
good
Dears,
Hello I want to create simple website. in website 3 user have been working. one is student, second is teacher and third is principle. when the student is a holiday, he fill the application form and submit to teacher not directly submited to principle. then teacher is checked the application and forward to principle. plz tell me how teacher forward application thorugh php and mysql. i just do not know forward. plz help me. tell me smiple method code or refrence link plz help me.
Thanks
awesome article i like it
dit is een proef mail
its very good
Can I use Oracle database?
plz tell me in easy way
lets see i have made a poster and on bottom of it i add email, your name and submitt. When i submit it shows the same page. even is we chnge its input name, id for match up. its still not matching
where i have to save php file? because i save my php file in folder Home/username/php/tests... cant match by system .
i need your help in web dewelopment
Weldone it really work
Hi
i have tried to view what a have send as a registration form, but i can't. Please i need your help!
here are the php codes
print_form
Provides a form submit button.
Submit buttons are processed the same as regular buttons, except they trigger the form's submit handler.
Properties:
#submit: Specifies an alternate callback for form submission when the submit button is pressed. Use '::methodName' format or an array containing the object and method name (for example, [ $this, 'methodName'] ).
#value: The text to be shown on the button.
Usage Example:
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this->t('Save'),
);
awesome article i like it
I will like to know if their is any one how can help me redirect script that usually submit in mysql database so it can be submission to email so I can use it on c-panel or shell. I am willing to pay if it can be done.
How do I connect allm that to the HTML form ??
how can I get information about my app Facebook and to send it to mysql
Sorry this idea is very complex to understand users and different from other sources it may be give some idea but does not give full idea there try to solve how to insert or retrieve data into or from based on or to the project!.
Mr. XYZ,
It is a suggestion to change the background of your page.
And change the visibility of content.
If someone need help from your website, how he/she will take help.
There is no match of mackground color and text color in your website......
Hi,
I need your help.
when I redirect webhook to form/show-data-post/ there are correct output (array and php code $_POST[...])
but where I redirect to my php script to catch POST data, array is blank, no data any more.
print_r($_POST);
$id_post = $_POST['submission_id'];
$id_form = $_POST['formID'];
$ip_addr = $_POST['ip'];
$nama = $_POST['nama'];
$mail = $_POST['email'];
where is the mistake?
please help me,
because I had already fallen in love with jotform :)
thanks
Can you just make a module that transmits everything from Jotform to a MySQL database including the pdf extensions?
Hi, good day. Can you make a video of this? So that it will be more clear. Thank you and I'm looking forward to your reply.
I want to create a form where, for example, a person enters a 7 digit number. Each number represents a different field, although when completing the form the person just records the 7 numbers in the text box. The php form would then pull out the values in the database fields. I don't know if that made sense but if you know what I mean does anyone know of a script/code for it? Many thanks!
your explanation looks like what i really want to do on my joomla project. but m confused! how do i get this form builder and use it on joomla.
Thank you.
Where I put the php code?
Its really great helpfull tutorials ,i solved this problem right here HELPFULL TUTORIALS
Hello, guys please help. Am learning programming. Have created the php script and a form that should enable me input data to a table in mysql data base but when I run, it literally does not input data but the following message is displayed." Parse error:syntax error, unexpected '$password'(T-VARIABLE)in C:xammphtdocswinsert.php on line 4.
Your help will be highly appreciated!
want to connect my php form with data base
how can submission show in app and website
What did you mean by this please " . You're done. Name the script as your thank you
php file and upload it to match the exact detail
that you have set in your Custom Thank You
URL "
Guys it works but you must correct some things in the above code depending on your database table/fields
I have used the code above and got errors that 'undefined index:name'. How do i correct that error and why does it bring that error?
I need to get data entered in a website form into my FileMaker database. There may be about 150 forms submitted per day. How can this be accoplished?
Hi I was just wondering is there a way to get this to work with SQL Server and not MySql?
Congratulations!!
Jotform is a great service!!
hi I have looked over several different tutorials on this subject and this far in for some reason I have not yet managed to get my form data into my database what are the chances if I give you my codes you can review them for m and *hopefully* shed some enlightening on me please........
the system I have been trying t use is as follows:
I have a rather crude looking form consisting of a method, action = post [to a PHP action file &
a text area & lastly a submit button........
and that's it nothing more in that html file;
the action file opens a DB connection my DB with my user name and p/w and of course the DB name
once I submit my form I receive my pre defined message that the data was saved so I know there are no error there however once I go in PHPmyadmin and look at my table there has been no data saved there since I manually inserted 2 rows
Congrats to all of the winners. Great job!
Hi,
Thank you for the incredible contest. Just want to ask when will the prizes be distributed? I've already filled up the form you sent via email. But I did not get any confirmation or follow up after that.
More Power and a Prosperous New Year!
Great Job WINNER'S..
These are great looking. Congratulations!! I envy your Jotform skills!!
its the best
How can I get additional prizes?
Congrats to all of the winners. Great job!
Congrats Jenn!
The winner doesn't even have anywhere to add your contact information...
Congratulations Jenn Schlick - a worthy win indeed!
Congratulations to all the winners - well deserved!
After the person submits the form, I would like to show a Thank You message. Is there some sort of code like below that could be place near the end of the php code?
if (mysql_query) === TRUE) {
echo "Thanks Dude!";
}
I submitted a form to my database but I searched the database and couldn't find the input. meanwhile it didn't display any error message
What is the appropriate way to handle checkboxes in mySQL? I've created a column in my db that maps to a checkbox field but when I submit data to it, it shows as Array rather than what has been selected. Thanks.
I have taken the code above, inserted what I need from my form as well as my sql database,and I am getting nothing
Can I email the info to someone for trouble shooting ?
If I have two fields that I want to merge, would the code be:
$phonenumber = $_POST['field1'] ."-". $_POST['field2'];
Then in my db this would appear in one column as 'field1' - 'field2'
do i have to put in the open php tag first
"
In the search ID section of the PHP script, I assume the 'table_name' has to be updated to my table name, is that correct?
Thanks for this tutorial, really helped us with lots of form inputting!
By the way, everyone should be using the 'mysqli_query' method to connect to MySQL databases as 'mysql_query' will be removed from PHP in future:
very nice
Nice explanation, what a pity that PHP is not really easy to learn.
hi,i try to run the form to mysql database and it was successful but i cant found the input inside the database.it also show me undefined variable in line 33.here is my codes
This is great, but how could I run a search on my database and prepopulate form input with data that already corresponds to an id before updating.
So now we can write the fields to a database, but now we need to read it back also and place it onto the page, do you have an example like above to show me how this is done?
Jotform folks
I just copy and the example provided and change all the parameters/string with my database information, but the following message has displayed:
Warning: mysql_numrows() expects parameter 1 to be resource, boolean given in line 33
Below is the 33 in my file. "$resultcount = mysql_numrows($sqlsearch);
"
Any help is greatly appreciated.
Thanks
Getting the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''lacrosse_test' (submission_id, formID, ip, fullname3, email4, newto) VALUE' at line 1
Any ideas?
I need to update my entries in my login page to my database i need coding help
Thank you, finally i found your tutorial was work for me after spend 6 hours just looking for update mysql.
Hello,
Thanks for the script. It works as charm for me. The only one problem I have is that when I include the item "file" for the submitted document. The thank you page shows me that : Unknown column 'file' in 'field list'
That's the code I have:
Hello,
I do have a concern as sometime jotform add some figures after the field I created.
Let say I add an input field name. On the Post I get on my page, the field that correspond to name is [name17]. Which of course cannot be inserted in my Database.
Of course in my landing page, I could make a script in order to recover the corresponding field but that would not always work
Do we have a possibility to put another tag for the input field (i want my label = name and the post id will be 'username')
Hello I created a form in here just jot form I tried to insert it for my school project where I wanted to implement the fumulário that I created with my SQL database in php.
I tried changing the script but without success, I am working on xampp but am not succeeding.
In my SQL table with the name (user has the following data:
login
pw
email
name
My database is called: headsport, host: localhost, name: root, and no password pw.
Note: on my registration form only has this login, pw, email, name.
Will anyone be able to adapt the script for my project?
Hugs, Dir3t
my dear sir if you know joomla plz clear my doubet
1> how can made registration form in joomla ?
2> how can add dynamic template page in inner page plz explain details and easy langauge
sorry, i mean it is not a primary key.
how to insert the data that have the same id with data in the database.
for example, i want to insert the data of branches from the customer master. so, it will send the customermasterId('8') and branchesId ('14') to the database.
however, in the database, it is already have a data with customermasterId ('8')
it means, how can i insert the data with multiple customermasterid. for your information, those id is not a foreign key.
yu no programi data base ighj df
Its works!, thank you. You save my job!.
how do you retrieve a form with the information in it and updating the information on the database using php
hello could i pay you to build my form of 10 fields to do the same = insert the data into mysql database.
Hi
I would like to created a submission form that is also able to 'send' the image,and some of the information on the form,directly to a page on my website so that it is displayed immediately(as well as saving everything to a database).
How is this achieved? Is this something that you can help with?
Cheers.
MJC
Hi,
My database is in OVH, how can I do to link my forms to my database?
thank you to yours answers
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /raid/vhost/guan-xi.com.tw/www/trymeok.php on line 43
Table 'vhost59811.table_name' doesn't exist
How should I do with this.
Thanks so much for this, works fine and got me kick started!
Getting an error upon submit:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '', '', 'Yes', '', 'Yes', '', 'Yes', '')' at line 4
Here is what I have from line 1 - 12 in my php page:
OlA , eu entrei no meu jotfrorm e passei pra amigos quando eles enviao algo ele falam que aparece Form Disabled
This form has been disabled
entao eu queria uma ajuda rapida
How to insert id into database after deleting previous one
Is it possible to get someone at Jotform to help us bridge via API to Solve360 CRM? We're wanting to stick with Jotform, but may have to switch to other form builders for integration ease of use.
See here:
I feel confident that someone at Jotform can solve this fairly easily... We just need to POST variables into a PHP script/wrapper right?
I use your form to attend my customer my seminars. I am not web developer is it possible to ad this script to my web site easily without code etc.