How do I send my Jotform submission to MySQL database?

  • Profile Image
    chakraology
    Asked on March 01, 2018 at 10:05 AM

    I'm trying to connect my contact form to send information to my database. I follow the instructions provided at this link:

    https://www.jotform.com/help/126-How-to-send-Submissions-to-Your-MySQL-Database-Using-PHP


    I loaded the php script at the root folder where my contact page is and the thank you page. 

    I can't seem to figure out why it's not working. My jot form is

    https://form.jotform.com/80521548584158

    I'm also including some screenshots of my database and the php script. 

    Any help would be greatly appreciated. 

    1519916684Screen Shot 2018-03-01 at 6.58

    1519916705Screen Shot 2018-03-01 at 6.58

  • Profile Image
    Sabbir
    Answered on March 01, 2018 at 11:11 AM

    The idea is to post the form data to your external PHP script to retrieve the form data and pass them to your mysql database.

    From your screenshot, I can see you are redirecting your form submission data to an html script rather than a php script.

    1519916705Screen Shot 2018-03-01 at 6.58

    Are you certain that you are getting the form data to your external page after you submit the form?

    Once you get the form data, you can insert them to your mysql database.

    If you need any further assistance on this, please let us know.

  • Profile Image
    chakraology
    Answered on March 01, 2018 at 05:27 PM

    Sabbir,

    When I had the link like this:

    http://chakraology.org/new/site/thankyou.php


    It showed me a page with all of the data displayed and nothing would populate in the database either. Is it the script? the script was in the same root folder as the php page. 

  • Profile Image
    jonathan
    Answered on March 01, 2018 at 06:40 PM

    We will not be able to review your custom PHP scripts from the URL link  http://chakraology.org/new/site/thankyou.php you provided since PHP are server-side scripts.

    ...It showed me a page with all of the data displayed

    You are halfway there already. You just need the PHP script to pull tha send post data and push it to your MySQL database.

    Please check the example from this website I found.

    Let us know if you need further assistance.




  • Profile Image
    chakraology
    Answered on March 01, 2018 at 07:28 PM

    So the thankyou.php page needs to be in  the thank you page like a css type script a the the top of the page? 

    The script in the thankyou.php page is the one in this article with all of the data from mysql server. 

    https://www.jotform.com/help/126-How-to-send-Submissions-to-Your-MySQL-Database-Using-PHP


    Because the jot form already has the post settings, correct? Sorry for my ignorance. I just thought this would be easier but eager to learn. 

  • Profile Image
    Kiran
    Answered on March 02, 2018 at 12:27 AM

    So the thankyou.php page needs to be in  the thank you page like a css type script a the the top of the page? 

    Yes. The MySQL query with the script should be placed in a PHP file and then the form needs to be redirected from the thank you page. As I check you JotForm, I see that the Thank you page is still redirecting to http://chakraology.org/new/thankyou.html. Please rename the file thankyou.html to thankyou.php in your server and try using the script from the guide with modification of field names in the query as per the table in the database and the fields in the form so that it should be working fine.

    If you need any further assistance, please provide us with the query from the script so that we can take a look and assist you further.

    Thanks!

  • Profile Image
    chakraology
    Answered on March 02, 2018 at 02:07 AM

    Okay, I now have a different problem. So I updated my thank you page to be 

    http://chakraology.org/new/thank_you.php

    When I fill out the form:

    https://form.jotform.com/80521548584158

    I get the following message:

    Access denied for user 'root'@'localhost' (using password: NO)

    I know that now it's not connecting to my database. Here is a screenshot of my database

    What am I missing now? I'm also attaching the script. 

    1519974229Screen Shot 2018-03-01 at 11.0


    <?php

    // This function will run within each post array including multi-dimensional arrays 

    function ExtendedAddslash(&$params)

            foreach ($params as &$var) {

                // check if $var is an array. If yes, it will start another ExtendedAddslash() function to loop to each key inside.

                is_array($var) ? ExtendedAddslash($var) : $var=addslashes($var);

                unset($var);

            }

     

    // Initialize ExtendedAddslash() function for every $_POST variable

    ExtendedAddslash($_POST);      

     

    $submission_id = $_POST['submission_id']; 

    $formID = $_POST['formID'];

    $ip = $_POST['ip'];

    $name = $_POST['name3'][0];$_POST['name3'][1];

    $email = $_POST['email4'];

    $city = $_POST['city5'];

    $state = $_POST['state6'];

    $sign = $_POST['sign'];

    $country = $_POST['country'];

     

    $db_host = 'localhost';

    $db_username = 'chakraol_contact';

    $db_password = 'zencontact555';

    $db_name = 'chakraol_database';

     

    mysql_connect( $localhost, $chakraol_contact, $zencontact555) or die(mysql_error());

    mysql_select_db($chakraol_database); 

     

    // search submission ID

     

    $query = "SELECT * FROM `contact_newsletter` WHERE `submission_id` = '$submission_id'";

    $sqlsearch = mysql_query($query);

    $resultcount = mysql_numrows($sqlsearch);

     

    if ($resultcount > 0) {

     

        mysql_query("UPDATE `contact_newsletter` SET 

                                    `name` = '$name',

                                    `email` = '$email',

                                    `city` = '$city',

                                    `state` = '$state',

                                    `sign` = '$sign',

                                    'country' = '$country'  

     

                                 WHERE `submission_id` = '$submission_id'") 

         or die(mysql_error());

        

    } else {

     

        mysql_query("INSERT INTO `contact_newsletter` (submission_id, formID, IP, name, email, city, state, sign, country) 

                                   VALUES ('$submission_id', '$formID', '$ip', '$name', '$email', '$city', '$state', '$sign', '$country') ") 

        or die(mysql_error());  

     

    }


    ?>

  • Profile Image
    Kiran
    Answered on March 02, 2018 at 03:31 AM

    Could you try adding the following statement right after <?php in the beginning of the code?

    print_r( $_POST ); 

    This should display the form submission data in the form of array in the Thank you page.

    Generally, the database should be connected using localhost. However, could you try using the IP address of your website (69.89.31.222) instead of localhost in the DB connection string to see if that works? We would also recommend to check with the hosting service provider to check if there is a different string can be used.

    Thanks!