samedi 25 avril 2015

Wordpress: checkboxes in plugin

I currently have this code...

    $wpdb->update( 
        $table_name_employee, 
        array( 
            'ID' => $_POST["user"], 
            'Role' => $_POST["Role"], 
            'Seniority' => $_POST["Seniority"], 
            'Payroll' => $_POST["Payroll"], 
            'ReportTo' => $_POST["ReportTo"], 
            'Tasks' => $_POST["Tasks"], 
        ), 
        array( 
            'ID' => $_POST["user"], 
        ) 
    );

The value of $_POST["Tasks"] is an array and not a string. It is derived from checkbox code...

...
<input type=checkbox name="Tasks[]" value="38"> Task 38
<input type=checkbox name="Tasks[]" value="39"> Task 39
<input type=checkbox name="Tasks[]" value="40"> Task 40
... many more

If I change Tasks[] to Task I only check the value of one checkbox. If I leave it as Tasks[] the value is passed as an array but the $wpdb->update() command above fails with this error:

Warning: mb_check_encoding() expects parameter 1 to be string, array given in /home/gj/public_html/matrix/bg/wp-includes/wp-db.php on line 2378

Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in /home/gj/public_html/matrix/bg/wp-includes/wp-db.php on line 1094

My question is: How do I correctly modify the $wpdb->update() above considering $_POST["Tasks"] is an array? Any searches I have made have been unsuccessful in showing a similar scenario.




Aucun commentaire:

Enregistrer un commentaire