Thanks for your help. I'm still having some problems though. I've put the below code into the functions.php file. I'm trying to run the query when I make a post with both categories 2 and 3 selected. But it's now breaking wordpress and not working. Do you know what I'm doing wrong? I'm pretty new to this stuff aren't very familar with if statements. any further help would be amazing.
function add_point( $query ) {
if ( $post_categories = array( 'category__and'=>array(2,3) )) {
mysqli_query($con,"UPDATE persons SET Age=Age+1
WHERE FirstName='Peter' AND LastName='Griffin'");
}
}
add_action( 'draft_to_publish', 'add_point' );