Support » Plugin: Participants Database » Which template sends/submits the data to the database

  • Resolved NicolasMous

    (@nicolasmous)



    Dear xnau,

    Lately i have been working with my own created code for checkbox searching / retrieving.

    The problem now is that i have created a piece of code that ‘gets’ the submitted checkboxes – turn it into a string variable and that string variable is being used in the query to retrieve the information. See code below:

    if(!empty($_POST['columns'])) { // empty() checks if the value is set before checking if it's empty.
    
        foreach($_POST['columns'] as $key_post=>$value_post){
    	// Runs mysql_real_escape_string() on every value encountered.
            $clean_criteria = array_map('mysql_real_escape_string', $_REQUEST['columns']);
    
            // Convert the array into a string.
            $criteria = implode("','",$clean_criteria);
    
        }
    	echo $criteria;
    	$tmp = $wpdb->get_results("
            SELECT
                name_of_living_lab, location_of_living_lab, type_of_living_lab, theme_of_living_lab, stage_of_living_lab, living_lab_document
            FROM
                wp_participants_database
            WHERE
    			stage_of_living_lab IN ('$criteria')
    		ORDER BY
    			name_of_living_lab ASC
        ");

    Though, the problem is that when i submit data to the database using checkbox, WordPress formats the value to the database into these weird characters: a:2:{i:0;s:0:””;i:1;s:10:”Prevention”;}

    I have read something about this and this can be fixed by coverting the passed data with unserialize, like so for example:

    $string = 'a:2:{i:0;s:0:"";i:1;s:10:"Prevention";}';
    $array = unserialize($string);

    The question however is where i can add this unserialize.. i think it should be done at the piece of code where the data is being submitted to the database. But which template and more specific, which line of code is that. Obvious the $string of the example will also not be a literal string but some sort of variable.

    https://wordpress.org/plugins/participants-database/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author xnau webdesign

    (@xnau)

    From your code, I don’t see where you’re getting a serialized array. $_REQUEST[‘columns’] wont be serialized, it will be an array if it comes from a multiselect.

    Array values are serialized before being stored in the database because you can’t store arrays in the database. This means that the value from the database must be unserialized when you get it back from the database…

    A serialized array is a way to represent (or store) an array as a string.

    Hmm ok, fair enough. But im trying to retrieve serialized data in the database (array values) based on the checkboxes that a user selects (the checkboxes values are the same of the stored arrays). I try’d to unserialize the values of the database but i find this quite hard to do especially with multiple serialized values which are being stored in a single variable.

    But i found a better solution with the use of a simple REGEXP in my query which kinda does the same as the unserialize.

    But thanks anyway!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Which template sends/submits the data to the database’ is closed to new replies.