Just on the off chance that errors are getting logged instead of displayed, you might want to add the following at the start of the script:
ini_set('display_errors', 1);
error_reporting(E_ALL);
You can delete that or comment it out once things are working.
If that doesn't tell you anything, you might want to throw in something like the following after your mysql_query() calls to see if any matches are actually being found:
if(mysql_num_rows($result) == 0)
{
user_error("No rows matched for query: $active_contracts", E_USER_WARNING);
}
(Change $active_contracts to $campaigns_per_target for the query in the foreach loop.)