• Resolved ace0930

    (@ace0930)


    Assume I got an empty input like <input id=test" type="text" name="test">

    Now get it with post and save it into a variable called data, and insert this data into the table, which looks like this:

    
    $data = isset ( $_POST['test'] ) ? $_POST['test'] : 'empty';
    
    if ( $data !== 'empty' ) {
       $new = sanitize_text_field ( $data );
       $wc_table_name = $wpdb -> prefix . 'my_table';
       $wpdb -> insert ( $wc_table_name, array ( 'name' => $new ) );
    }
    

    You would notice that it creates an empty row in the table if you submit the input with no value. The value is empty even without a space when I check it in the table of the database.

Viewing 1 replies (of 1 total)
  • Thread Starter ace0930

    (@ace0930)

    I found that the problem is not the wpdb::insert but the isset(). I should use !empty to check because isset() return true. (the variable is defined and not null)

Viewing 1 replies (of 1 total)
  • The topic ‘bug with wpdb::insert’ is closed to new replies.