bug with wpdb::insert | WordPress.org

[ad_1]

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.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer