Compare custom-field value of entry to registration-form field value before saving user Whoo, that title is a mouthful...

I'm trying to check against a unique school "code" that an athlete has to input to register with a team. The code is different based on what team they are trying to join (referenced in a segment of registration page URL). I have no idea what I'm doing when it comes to PHP or plugins but I hope I'm on the right track. I have no idea how to test what values my variables have.

I've essentially copied the user/SaveUser controller into my own plugin (I have to place user in Athlete user group &amp; related the specific team entry to user, hence custom plugin) and placed snippet below right before the if (craft()-&gt;users-&gt;saveUser($user)) line.

$teamName = craft()-&gt;request-&gt;getPost('fields.teamName');
//Get team name, set in hidden input in form, which was grabbed from segment


$criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
$criteria-&gt;section = 'teams';
$criteria-&gt;title   = $teamName;
$criteria-&gt;limit   = 1;
$entry = $criteria-&gt;first();
//Find the Team entry in my 'teams' section

$schoolCode = $entry-&gt;schoolCode;
//Place value of schoolCode field in variable

$codeInput = craft()-&gt;request-&gt;getPost('fields.schoolCode');
//Grab user's input

if ($schoolCode == $codeInput)
{ 
    craft()-&gt;users-&gt;saveUser($user)
}


This is, of course, not working. I'm not getting any errors either.

Am I anywhere close to doing this right?
Thanks to Brad Bell, I was able to troubleshoot using var_dump. The code above works correctly, but I'm unaware of how to do a simple validation of the code within the controller, w/o creating a new model, &amp; send back a response.

Instead (for simplicity on my end), when the validation fails, I redirected to an error specific page, referencing the code entered &amp; team name.