How do I check if my $wpdb->insert() was successful?

It returns either the number of rows inserted or false on error.

Maybe you can get id of inserted recode or false if the insert fails:

refer link: https://developer.wordpress.org/reference/classes/wpdb/insert/#return

So you can check like below:

$result_check = $wpdb->insert( $table, array("name"  => $name, "email" => $email));
if($result_check){
   //successfully inserted.
}else{
  //something gone wrong
}

Leave a Comment