bug with wpdb::insert
-
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)
Viewing 1 replies (of 1 total)
- The topic ‘bug with wpdb::insert’ is closed to new replies.