I'd do it with this structure:
PHP Code:
function AddMoreExp()
{
currentexperience ++;
if (currentexperience >= maxexperience) {
LevelUp();
}
}
function LevelUp()
{
if (currentexperience < maxexperience) {
echo("AHMAGAWD CORRUPT STAFF SLASH HACKER ALERT!!!");
return;
}
currentexperience -= maxexperience;
// Level up!
}
Rough draft, but you get the idea.