-1

Iam trying to insert Array data (ie., checkbox values) into Mysql db (using Phpmyadmin)

when I try to store, iam getting as 'Array' for the field "forms" in db..

please someone tell me what changes I have to do for the below code, so I can store all the array values (seperated with commas in my db)

here is the code:

if(isset($_POST['forms']) && $_POST['forms']!=''){
        $table = $wpdb->prefix . "eshop_orders";
        $forms=$wpdb->escape($_POST['forms']);


        $query1=$wpdb->query("UPDATE $table SET forms='$forms' where checkid='$checkid' limit 1");
    }

waiitng for replies..

4

1 回答 1

1

Since $forms is an array, you either need to serialize() it or convert it into a string before inserting. Which method you choose is up to you and what makes more sense.

// convert to comma separated string
$forms = $wpdb->escape( implode(',', $_POST['forms']) );

// or

// serialize the PHP array, use unserialize when you retrieve it
$forms = $wpdb->escape( serialize($_POST['forms']) );
于 2012-10-21T20:33:50.667 回答