Configurable list widget to sql database

  • terrywells
    Asked on January 6, 2016 at 4:35 PM

    Hi, I have managed to work out how to get the form submissions to sql using php. The configurable list widget, predictably, appears in one field. As it seems to be a sub-table within the form is it possible to split it into separate fields in the database using php?

    Thank you.

    This is the php I am using, 'sightings' is the configurable list widget:

    <?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['fullname'][0] ." ". $_POST['fullname'][1];
    $email = $_POST['email'];
    $date = $_POST['date5'][0] ."-". $_POST['date5'][1] ."-". $_POST['date5'][2];
    $location = $_POST['location'];
    $sightings = $_POST['sightings'];
    $clickto = $_POST['clickto'];

    $db_host  = "db606819711.db.1and1.com";
        $db_name   = "db606819711";
        $db_username  = "dbo606819711";
        $db_password   = "*************";

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

    // search submission ID

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

    if ($resultcount > 0) {
     
        mysql_query("UPDATE `sightings` SET
                                    `fullname` = '$name',
                                    `email` = '$email',
                                    `date5` = '$date',
                                    `location` = '$location',
                    `sightings` = '$sightings',
                    `clickto` = '$clickto'    
                                 WHERE `submission_id` = '$submission_id'")
         or die(mysql_error());
      
    } else {

        mysql_query("INSERT INTO `sightings` (submission_id, formID, IP,
                                                                              fullname, email, date5, location, sightings, clickto)
                                   VALUES ('$submission_id', '$formID', '$ip',
                                                     '$name', '$email', '$date', '$location', '$sightings', '$clickto') ")
        or die(mysql_error());

    }
    ?>

  • Elton Support Team Lead
    Replied on January 6, 2016 at 11:26 PM

    Config List Widget contains multiple fields so you will get a json array data out of it.

    Example:

    Configurable list widget to sql database Image 1 Screenshot 20

    So to get the value, it's either you will decode this data into php using json_decode and then use foreach function to get its value. You might find this helpful http://stackoverflow.com/questions/12429029/php-get-values-from-json-encode.

    If you need further assistance, do let us know.