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

    Post data is sent, but not being saved in MySQL

    Asked by memaxt on January 08, 2015 at 09:30 PM

    Hi there,

    I have a test form which is meant to send data to MySQL

    Test form:LINK

    When I submit it goes to a blank page which is fine for the time being. but anyway the problem is the data sent from this form isn't appearing in my database.

    Here is my .php code to send data:

     

    // 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['name'];

     

    $db_host = 'xxxxx';

     $db_username = 'xxxxx';

     $db_password = 'xxxxx';

     $db_name = 'xxxxx';

     

    mysql_connect( $db_host, $db_username, $db_password) or die(mysql_error());

    mysql_select_db($db_name); 

     

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

     $sqlsearch = mysql_query($query);

     

    $resultcount = mysql_numrows($sqlsearch); 

    if ($resultcount > 0) {

     

    mysql_query("UPDATE `cdr_jotform` SET `name` = '$name'

                                        

    WHERE `submission_id` = '$submission_id'") 

    or die(mysql_error());

        

    } else { 

    mysql_query("INSERT INTO `cdr_jotform` (submission_id, formID, IP, name) 

     

    VALUES ('$submission_id', '$formID', '$ip','$name')")  

     or die(mysql_error());  

    }

    ?>

     

    I created a table in MySQL called:cdr_jotform

    any ideas why its not posting my data?

     

     

    POST MySQL POST data send POST
  • Profile Image

    Answered by memaxt on January 09, 2015 at 06:51 AM

    sorry to bump...I need to rectify this swiftly as possible. Help would be very much appreciated.

  • Profile Image

    Answered by Ben on January 09, 2015 at 10:48 AM

    Hi,

    Unfortunately bumps do not work here - your thread does not get moved forward as we reply based on the time posted, so earlier the post, earlier we come to it.

    Can I ask you where you got the code for ExtendedAddslash from?

     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);
             }
     }

    I think I saw it on StackOverflow before, but I ask since there was another thread with similar issue before.

    The issue here is that you are basically doing next:

    0. {data}

    1. go to this function to remove slashes

    2. if array recurse into by going to step 1

    3. add slashes

    4. destroy the variable

    5. -- no data --

    Because of the 4th step, you are not able to get any variables in.

    To resolve it just remove it from the code (or comment it out).

    Do let us know how it goes.

    Best Regards,
    Ben

  • Profile Image

    Answered by memaxt on January 09, 2015 at 11:01 AM

    Hi Ben,

    Many thanks for your response, I got this code off here, Jotform provide a guide to which i copied and pasted it into a blank .php file and amended the host, username, password, database name and fields required and table name.

    I removed the following from my .php

     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);
             }
     }

     

    but still I'm not receiving any data :(

     

  • Profile Image

    Answered by Ben on January 09, 2015 at 01:06 PM

    Hi,

    I apologize for that and thank you, we will look for it and fix the guide.

    Can you please confirm if you have the starting <?php in your file? Based on your code above it seems to be missing.

    Also, if you would not mind adding the entire code you have in the pastebin.com or pastie.org which would allow us to take a better look at it since here on forum some parts might be stripped down?

    Since your jotform is already set to send the POST data did you check if it is actually sending it (which it should)? If you did not test it, please take a look here: How to Post Submission Data to Thank You Page

    Another reason why it would not save data might be that your connection to your database is not working, or that you do not have the right fields available in your DB:

    For example, if this is Database name: cdr_jotform then you would need to alter the code to use the name during the connection, and use the table name in the SQL statements.

    Best Regards,
    Ben