Having problems with Mysql and and data entry

  • Profile Image
    martylflorence
    Asked on January 25, 2012 at 04:53 AM

    My problem is, when I submit the form only the "Form ID and IP" are being entered into the data base here is my php code what is wrong?

     


    // 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'];
    $email = $_POST['email'];
    $phonenumber = $_POST['phonenumber13'][0] ."-". $_POST['phonenumber13'][1];
    $subject = $_POST['subject7'];
    $message = $_POST['message6'];

    $db_host = 'mysql17.000webhost.com';
    $db_username = 'xxxx_xxxxxxxx';
    $db_password = 'xxxxx';
    $db_name = 'xxxxxxx';

    mysql_connect( 'mysql17.000webhost.com', $db_username, $db_password) or die(mysql_error());
    mysql_select_db($db_name);

    // search submission ID

    $query = "SELECT * FROM `table_name` WHERE `submission_id` = '$submission_id'";
    $sqlsearch = mysql_query($query);
    $resultcount = mysql_numrows($sqlsearch);

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

        mysql_query("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(mysql_error());

    }

     

  • Profile Image
    liyam
    Answered on January 25, 2012 at 05:20 AM

    Hello, have you tried doing this script to see all the proper variables generated by the post data?

    <?php

    var_dump($_POST);

    ?>

  • Profile Image
    martylflorence
    Answered on January 25, 2012 at 05:21 AM

    Would I have to run that as a seperate script or as apart of the above?

  • Profile Image
    liyam
    Answered on January 25, 2012 at 07:08 AM

    It's up to you.  But as a suggestion, just comment out the rest of the script so that it will not try to initialize to make a database insert. 

    The purpose of using the var_dump(); function is to see if you have the proper variables being passed to your own php script.

    As you have stated, only the formID and the IP are the ones showing up when you do the submission, then this means that you have the two variables correct while the rest are not.

    Once you see the returned variables, you will be able to identify what should be used so you get to properly insert the data required.

    Just let us know if you need further assistance.

  • Profile Image
    khrisell
    Answered on July 05, 2013 at 12:03 AM
    Greetings!

    We are happy to announce that we have released Jotform Webhooks,  this feature would replace Send Post Data + Custom URL Thank You Page workaround in order to help you transfer forms data to your own database using your own script codes.

    To know more about Jotform Webhooks, please click here.

     

    Thank you for using JotForm. :)