When I send data to wpdb from form I can have some empty fields. How can I add conditions to array of data inside array or before insert wpdb to send only filled fields ?

The fields concerned (for example $serializedpaisol has no value(empty)) have already be checked to know if values exist, but the wpdb->insert find always this data name but is empty:

    $serializedpaisol = maybe_serialize($paisol);
$data = array(
        'name' => $_POST['aacl_title'],
        'nicname' => $Acronyme,
        'img' => $idImage,
        'info' => $_POST['aac_description'],
        'resume' => $_POST['aac_resume'],
        'statut' => $serializedcp,
        'mgmt_act' => 1,
        'website' => $serializedurllink,
        'payment_solutions' => $serializedpaisol,
        'mail'=> $mail,
        'tel'=> $tel,
        'location'=> $serializedloc,
        'date'=> $timeday
    $format = array('%d','%s','%s','%d','%s','%s','%s','%d','%s','%s','%s','%s','%s','%s');
    $table = $wpdb->prefix.'table_data';

When I send form I get "Notice: Undefined variable: serializedpaisol"

I don't understand well wpdb::prepare , does it check the existence of data value before to send to database ?

1 Answer 1


Hi the error you are getting for $serializedpaisol variable because it is not define in function scope.

the variable you define in specific scope can not access out form its scope;


//example scope
echo $var; // you will get undefined error.

how you can fixed it?


// first define variable in function  scope

$serializedpaisol ="";

    $serializedpaisol = maybe_serialize($paisol);
echo $serializedpaisol; // now you will not get any error.

hope you understand the point.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.