RFID Card Adding/Removing - Help please

Hello I am making a RFID RC522 door lock. I've got the basics, everything works right except of Card adding and removing. It kinda works till u remove and add card for several times, then it starts to overwrite the previous card strings and it has access even after Remove message (because of the overwrite of the previous card). I would like to store 10 cards till the restart (as shown below).
Here's the part of the code about adding and removing:

if (card1 == "" && strID != masterC) {
              card1 = strID;
              menuConfirmed();
              cardAdd();
              menuMode1 = false;
              Serial.println("Card1 added");
              goto main;
          }
          if (strID == card1 && strID != masterC) {
            card1 = "";
            menuConfirmed();
            cardRem();
            menuMode1 = false;
            Serial.println("Card1 removed");
            goto main;
          }
          if (card2 == "" && strID != masterC) {
              card2 = strID;
              menuConfirmed();
              cardAdd();
              menuMode1 = false;
              Serial.println("Card2 added");
              goto main;
          } 
          if (strID == card2 && strID != masterC) {
            card2 = "";
            menuConfirmed();
            cardRem();
            menuMode1 = false;
            Serial.println("Card2 removed");
            goto main;
          }
          if (card3 == "" && strID != masterC) {
              card3 = strID;
              menuConfirmed();
              cardAdd();
              menuMode1 = false;
              Serial.println("Card3 added");
              goto main;
          }
         if (strID == card3 && strID != masterC) {
            card3 = "";
            menuConfirmed();
            cardRem();
            menuMode1 = false;
            Serial.println("Card3 removed");
            goto main;
          }
         if (card4 == "" && strID != masterC) {
              card4 = strID;
              menuConfirmed();
              cardAdd();
              menuMode1 = false;
              Serial.println("Card4 added");
              goto main;
          }
          if (strID == card4 && strID != masterC) {
            card4 = "";
            menuConfirmed();
            cardRem();
            menuMode1 = false;
            Serial.println("Card4 removed");
            goto main;
          }
          if (card5 == "" && strID != masterC) {
              card5 = strID;
              menuConfirmed();
              cardAdd();
              menuMode1 = false;
              Serial.println("Card5 added");
              goto main;
          } 
          if (strID == card5 && strID != masterC) {
            card5 = "";
            menuConfirmed();
            cardRem();
            menuMode1 = false;
            Serial.println("Card5 removed");
            goto main;
          }
          if (card6 == "" && strID != masterC) {
              card6 = strID;
              menuConfirmed();
              cardAdd();
              menuMode1 = false;
              Serial.println("Card6 added");
              goto main;
          } 
          if (strID == card6 && strID != masterC) {
            card6 = "";
            menuConfirmed();
            cardRem();
            menuMode1 = false;
            Serial.println("Card6 removed");
            goto main;
          }
         if (card7 == "" && strID != masterC) {
              card7 = strID;
              menuConfirmed();
              cardAdd();
              menuMode1 = false;
              Serial.println("Card7 added");
              goto main;
          }
          if (strID == card7 && strID != masterC) {
            card7 = "";
            menuConfirmed();
            cardRem();
            menuMode1 = false;
            Serial.println("Card7 removed");
            goto main;
          }
          if (card8 == "" && strID != masterC) {
              card8 = strID;
              menuConfirmed();
              cardAdd();
              menuMode1 = false;
              Serial.println("Card8 added");
              goto main;
          } 
          if (strID == card8 && strID != masterC) {
            card8 = "";
            menuConfirmed();
            cardRem();
            menuMode1 = false;
            Serial.println("Card8 removed");
            goto main;
          }
          if (card9 == "" && strID != masterC) {
              card9 = strID;
              menuConfirmed();
              cardAdd();
              menuMode1 = false;
              Serial.println("Card9 added");
              goto main;
          } 
          if (strID == card9 && strID != masterC) {
            card9 = "";
            menuConfirmed();
            cardRem();
            menuMode1 = false;
            Serial.println("Card9 removed");
            goto main;
          }
         if (card10 == "" && strID != masterC) {
              card10 = strID;
              menuConfirmed();
              cardAdd();
              menuMode1 = false;
              Serial.println("Card10 added");
              goto main;
          } 
          if (strID == card10 && strID != masterC) {
            card10 = "";
            menuConfirmed();
            cardRem();
            menuMode1 = false;
            Serial.println("Card10 removed");
            goto main;
          }
      if (strID == masterC) {
          menuMode1 = false;
          locked();
          goto main;
      }

Get rid of all the "goto" statements. Never use that. By doing what you are doing, you are flooding the stack with addresses until memory is exhausted.

Paul

When you have more than 2 or 3 variables whose names are different only in a trailing number, you should be using an array.

const byte NumberOfCards = 11;  // Use first for Master Card
String CardList[NumberOfCards];


// Add if not present.  Remove if present.
void DoCard(String strID)
{
  // Don't touch the Master Card
  if (strID == CardList[0])
    return;


  // Check to see if the card is already registered
  for (byte i = 1; i < NumberOfCards; i++)
  {
    if (CardList[i] == strID)
    {
      CardList[i] = "";
      menuConfirmed();
      cardRem();
      menuMode1 = false;
      Serial.print("Card");
      Serial.print(i);
      Serial.println(" removed");
      return;
    }
  }


  // Not present.  Add to the first available space
  for (byte i = 1; i < NumberOfCards; i++)
  {
    if (CardList[i] == "")
    {
      CardList[i] = strID;
      menuConfirmed();
      cardAdd();
      menuMode1 = false;
      Serial.print("Card added in location ");
      Serial.println(i);
      return;
    }
  }
  Serial.println("NO SPACE AVAILABLE!");
}

Paul_KD7HB:
Get rid of all the "goto" statements. Never use that. By doing what you are doing, you are flooding the stack with addresses until memory is exhausted.

Paul

Thanks for an advice, I have some code above the adding/removing code, so do you think removing that goto(s) are a good way of doing it? Do you think return is better in that way?

johnwasser:
When you have more than 2 or 3 variables whose names are different only in a trailing number, you should be using an array.

const byte NumberOfCards = 11;  // Use first for Master Card

String CardList[NumberOfCards];

// Add if not present.  Remove if present.
void DoCard(String strID)
{
 // Don’t touch the Master Card
 if (strID == CardList[0])
   return;

// Check to see if the card is already registered
 for (byte i = 1; i < NumberOfCards; i++)
 {
   if (CardList[i] == strID)
   {
     CardList[i] = “”;
     menuConfirmed();
     cardRem();
     menuMode1 = false;
     Serial.print(“Card”);
     Serial.print(i);
     Serial.println(" removed");
     return;
   }
 }

// Not present.  Add to the first available space
 for (byte i = 1; i < NumberOfCards; i++)
 {
   if (CardList[i] == “”)
   {
     CardList[i] = strID;
     menuConfirmed();
     cardAdd();
     menuMode1 = false;
     Serial.print("Card added in location ");
     Serial.println(i);
     return;
   }
 }
 Serial.println(“NO SPACE AVAILABLE!”);
}

Thank you for answering. I tried the same thing as you before, but never went right because the strID contains “:” , letters and numbers and that didn’t go well with an array, when i scanned the second card, none of them was working because it couldn’t handle custom symbols from strID. Thanks for help anyways, I really appreciate your help.

Xarakas:
never went right because the strID contains ":" , letters and numbers and that didn't go well with an array

When comparing one String with another it does not matter if the String is in an array or not. Something is going wrong and it could very well be in the part of your sketch that you did not show. I would be happy to help you fix the problem if you care to share your entire sketch.