What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    How to send submissions to your postgreSQL database using PHP

    Asked by rrm364 on October 07, 2014 at 01:32 PM

    Hi!

               I'm thinking about integrating JotForm with my postgreSQL. I saw this link on integrating MySQL with JotForm. Are there any different steps I would have to use if I wanted to integrate with postgreSQL? Thanks a lot!

    - Ravi Mehta

    Submissions JotForm different integrate postgreSQL
  • Profile Image

    Answered by Ben on October 07, 2014 at 04:30 PM

    Hi Ravi,

    Yes, you should be able to connect, but you will need to make some alterations from the code provided under that link.

    You can follow the steps here integrating JotForms with MySQL to step 2, then with step 3 come back here:

    ----------------------------------------------------------------------------

    Step 3:  Now we initialize the database connectivity for the script to PostgreSQL


    $db_host = 'db hostname here'; //most of the time this is localhost - your host provides you with this
    $db_username = 'db username here';
    $db_password = 'db password here';
    $db_name = 'name of your database';

    $db_port = ''; //Usually you do not change this as the database should tell you on which port it is connecting..
    $con_string = 'host='.$db_host.' dbname='.$db_name.' user='.$db_username.' password='.$db_password';
    $con = pg_connect($con_string) or die('Error connecting to database:"'.$
    con_string.'"');

    ?>

    Step 4: To check if an insert or an update should be done, a search should be initialized if the submission ID exists and then set a condition that if the submission ID exists, an update should be initialized using that submission ID.  And if there is no submission ID matching, then a new insert is going to be made:


    // search submission ID

    $query = "SELECT * FROM `table_name` WHERE `submission_id` = '$submission_id'";
    $sqlsearch = pg_query(
    $con, $query);
    $resultcount = pg_numrows(
    $sqlsearch);

    if ($resultcount > 0) {
     
        pg_query(
    $con,"UPDATE `table_name` SET
                                    `name` = '$name',
                                    `email` = '$email',
                                    `phone` = '$phonenumber',
                                    `subject` = '$subject',
                                    `message` = '$message'       
                                 WHERE `submission_id` = '$submission_id'")
         or die(
    pg_last_error());
       
    } else {

        pq_query(
    $con,"INSERT INTO `table_name` (submission_id, formID, IP,
                                                                              name, email, phone, subject, message)
                                   VALUES ('$submission_id', '$formID', '$ip',
                                                     '$name', '$email', '$phonenumber', '$subject', '$message') ")
        or die(pg_last_error()); 

    }
    ?>

    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

    --------------------------------

    That should be it :)

    You should now have your jotform integrated with PostgreSQL.

    The entire script (from step 3 to the end) should look like this (I will remove formatting from it).

    <?php

    /* Jotform to postgreSQL integration

        - Things to note:
            * The values that you can enter into the database are different per jotform, so please check the link for MySQL integration found here http://www.jotform.com/help/126-How-to-send-Submissions-to-Your-MySQL-Database-Using-PHP because this is only a supplement to that guide.

    */

    $db_host = 'db hostname here'; //most of the time this is localhost - your host provides you with this
    $db_username = 'db username here';
    $db_password = 'db password here';
    $db_name = 'name of your database';
    $db_port = ''; //Usually you do not change this as the database should tell you on which port it is connecting..

    $con_string = 'host='.$db_host.' dbname='.$db_name.' user='.$db_username.' password='.$db_password';
    $con = pg_connect($con_string) or die('Error connecting to database:"'.$con_string.'"');

    // search submission ID

    $query = "SELECT * FROM `table_name` WHERE `submission_id` = '$submission_id'";
    $sqlsearch = pg_query($con, $query);
    $resultcount = pg_numrows($sqlsearch);

    if ($resultcount > 0) {
     
        pg_query($con,"UPDATE `table_name` SET
                                    `name` = '$name',
                                    `email` = '$email',
                                    `phone` = '$phonenumber',
                                    `subject` = '$subject',
                                    `message` = '$message'      
                                 WHERE `submission_id` = '$submission_id'")
         or die(pg_last_error());
      
    } else {

        pq_query($con,"INSERT INTO `table_name` (submission_id, formID, IP,
                                                                              name, email, phone, subject, message)
                                   VALUES ('$submission_id', '$formID', '$ip',
                                                     '$name', '$email', '$phonenumber', '$subject', '$message') ")
        or die(pg_last_error());

    }
    ?>

    Do let us know if you have any questions.

    Best Regards,
    Ben

  • Profile Image

    Answered by rrm364 on November 04, 2014 at 12:11 AM

    Hi,

               I was wondering if there was any way to this while staying with Python. I don't need to know exactly how to do this, but would just like to get an idea of what tools I should use.

  • Profile Image
    JotForm Support

    Answered by Jan on November 04, 2014 at 07:06 AM

    Hi,

    Unfortunately, this guide about sending submissions to SQL database is only for PHP. We currently don't have a guide in doing this using Python.

    I'm actually not sure how to answer your question about what tools to use. You need to have a basic understanding on how mySQL databases works. (Which I can see you already know). A basic understanding about PHP would help.

    Please get back to use if you have further questions. Thank you for using JotForm.