How to manipulate field with Number of value "unlimited" through php
Those if($counter++ = 8) lines look whacky to me.

don't you mean:

$counter++;
if( $counter == 8 ) {
  /* do stuff */
}


checking for equality is == or === not =