I want to show a generic error message to a user when a database query fails on my site. I'm new to wordpress and I'm not sure how to go about it. I have the following function in my functions.php which gets called when the user submits a form:
function mytheme_insert_new_team() {
$name = $_POST['team_name'];
$type = $_POST['team_type'];
global $wpdb;
$table_name = "teams";
$response = $wpdb->insert($table_name, array(
'team_name' => $name,
'team_type' => $type
),array(
'%s',
'%s'));
if(!$response){
//an error has occured
}else{
//success, redirect user to the next step.
mytheme_redirect_invite_others($name);
}
}
I thought about echoing a "<p class='error'>An error occured.</p>"
but it didn't work. I also tried using the $errors global but I couldn't seem to get that working either. I want to sent the error back to the page with the form and display it above the form. How do I do this?
Happy to provide more information if needed.
Thanks in advance for your help!