Getting value from database table depending on field value

My guess is that this is the wrong hook for what you are trying to do, or you are using it incorrectly.

A few notes:

You are passing unvalidated data into a query. Please don’t do that. This…

$town_b = $_POST['item_meta'][800];//Gets the value from the first field
global $wpdb;

$query = "SELECT County FROM wp_locations WHERE Town = $town_b";

… is begging to be hacked. Any data in $_POST['item_meta'][800] hits the DB unfiltered. Very dangerous. Use prepare, at the very least.

$query = $wpdb->prepare("SELECT County FROM wp_locations WHERE Town = %s",$town_b);

Second, you’ve hook into what is pretty obviously a field validation system but you are trying to set a $_POST value. That is clearly not what it is meant for. So you are either too late or too early setting the value, or something. It is hard to tell with your two functions out of context the way they are. I can almost guarantee that you need to be using another hook though. Add some more detail and I will see about editing with a more specific answer.