My Sketch Crashes After Performing POST

I am trying to POST 2 times onto a website but the Sketch keep on crashing and it starts over from Setup?

It goes into Setup -> that is where my first POST is
Then it goes into Loop -> that is where my second POST is
I want my 2 POST to happen again and again with some delay but the POST in the Loop keep on crashing.
and my sketch starts all over from the Setup.

I am using Arduino Uno.
I have also attached a Keypad and 16x2 LCD to it.

Oh, aye, if only we could see your sketch we could help you.

Hi.. Here is my code it is a bit long so i have posted in 2 replies

#include <Keypad.h>          // Include the Keypad library.
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>


const byte rows = 4;          // Define the amount of rows and columns for the keypad.
const byte cols = 4;

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
char server[] = "beta1.tossdown.com";
//char server[] = "tossdown.com";
IPAddress ip(192, 168, 5, 34);
EthernetClient client;

LiquidCrystal lcd(A1,A0,A5,A4,A3,A2);
char keys[rows][cols] = {      // Define the characters of the keypad.
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[rows] = {9,8,7,6};    // Define the pins connected to the keypad.
//byte colPins[cols] = {5,4,3,2};
byte colPins[cols] = {5,3,2,1};
//byte colPins[cols] = {5,12,11,10};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);      // Initialize the keypad.

void setup()
{
  Serial.begin(9600);
  //while (!Serial) {
  //  ; // wait for serial port to connect. Needed for native USB port only
  //}
  
  MainSet();
  getNumber();
  clientConnect();
  Serial.println();
  Serial.println("########################################");
}

void loop()
{
  MainSet();
  getNumber();
  clientConnect();
}
//---------------------------------
int i = 0;
char* ourCode = "13467913";      // Set the required PIN code.
char* ourCode1 = "********";
char key;

void MainSet()
{
  i =0;
  ourCode1[0] = '*';ourCode1[1] = '*';ourCode1[2] = '*';ourCode1[3] = '*';ourCode1[4] = '*';ourCode1[5] = '*';ourCode1[6] = '*';ourCode1[7] = '*';
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print("Enter Card #");
}

void getNumber()
{ 
    while(i!=8)
    {
      char key = keypad.getKey();      // Get the key press from the keypad.  
         //Serial.println(key);      
        if (int(key) !=0)
        {   
            if(key == '0' || key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9')
            { 
                lcd.setCursor(i,1);
                //lcd.print(ourCode1[i]);
                ourCode1[i] = key;
                lcd.print(ourCode1[i]);
                i++;
            }
            else if (key == '*')   // To clear Screen if wrong number/digit entered  
            {
                i=0;
                ourCode1[0] = '*';ourCode1[1] = '*';ourCode1[2] = '*';ourCode1[3] = '*';ourCode1[4] = '*';ourCode1[5] = '*';ourCode1[6] = '*';ourCode1[7] = '*';
                lcd.clear();
                MainSet();
            }
            else if (key == 'A' || key == 'B' || key == 'C' || key || 'D' || key == '#')
            {
                i=0;
                ourCode1[0] = '*';ourCode1[1] = '*';ourCode1[2] = '*';ourCode1[3] = '*';ourCode1[4] = '*';ourCode1[5] = '*';ourCode1[6] = '*';ourCode1[7] = '*';
                lcd.setCursor(0,2);
                lcd.print("Invalid Input");
                delay(1000);
                lcd.clear();
                MainSet();
            }
        } 
    } i = 0;
}

int size1=0;
char buffer1[200];
String readServer = "";
String readServer1 = "";
String readServer2 = "";
bool check = false;

This is the second part of my code
I am using this function in the above reply or code

void clientConnect()
{ 
 if (Ethernet.begin(mac) == 0) {
   Serial.println("Failed to configure Ethernet using DHCP");
   // try to congifure using IP address instead of DHCP:
   Ethernet.begin(mac, ip);
 }
 
 Serial.println("connecting...");
 // if you get a connection, report back via serial:
 
 if (client.connect(server, 80)) {
 
       Serial.println("connected");
       // Make a HTTP request: 
       
         //String b = "rid=18&bid=18&khaba_card=24990435";
         String rid = "18";
         String bid = "18";
         String cardN = ourCode1;
         Serial.println(cardN); 
         String b = "";
         b = "rid="+rid;
         b +=  "&bid="+bid;
         b +=  "&khaba_card="+cardN;
         Serial.println(b); 
         client.println("POST /api/verify_khaba_test HTTP/1.0"); 
         //client.println("Host: tossdown.com");
         client.println("Host: beta1.tossdown.com"); 
         client.println("User-Agent: Arduino/1.0"); 
         client.println("Connection: close");
         client.println("Content-Type: application/x-www-form-urlencoded"); 
         client.print("Content-Length: "); 
         client.println(b.length()); 
         client.println(); 
         client.println(b);
   //      Serial.println("Sent data: " + b);
   //      client.println();
} else {
     // if you didn't get a connection to the server:
     Serial.println("connection failed");
  }

bool t = false;

while(t == false){
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) 
{
     //Serial.println("client available");
     char c = client.read();
     //Serial.print(c);
     // Removing everything before the start and including of ?> 
     if (c == '?' && i == 0)
     {
       c = client.read();
       if(c == '>')
       {
         check = true; // check to start storeing next chracter if the last one was ?>
         i ++;
         c = client.read();
       }
     }
    //if(c == '\n' || c == ' ') // Removes new lines but space is not working
      // c = client.read();
         
     // Storing the strings of XML
     if(check == true)
     { 
       Serial.print(c);
       buffer1[size1] = c;
       //readServer += c;
       size1++;
     }
 }
    
     // if the server's disconnected, stop the client:
     if (!client.connected()) 
     {
         Serial.println();
         Serial.println("------------------------------------------------------");
         Serial.println();
         int k = 0;
           //    FOR <status></status>  
           k = 0;
           while(k<size1)
             {
                 if(buffer1[k] == '<'){
                   if(buffer1[k+1] == 's' && buffer1[k+2] == 't' && buffer1[k+3] == 'a' && buffer1[k+4] == 't' && buffer1[k+5] == 'u' && buffer1[k+6] == 's'){
                     if(buffer1[k+7] == '>'){
                         k= k +8;
                         while(buffer1[k] != '<' && buffer1[k+1] != '/'&& buffer1[k+8] != '>'){
                             //Serial.print(buffer1[k]);
                             //readServer += buffer1[k];
                             k++;
   
                           }
                           Serial.println();
                     }  
                   }
                 }
                 k++;
             }
             //readServer += " ";
             k = 0;
             //    FOR <name></name>
           while(k<size1)
             {
                 if(buffer1[k] == '<'){
                   if(buffer1[k+1] == 'n' && buffer1[k+2] == 'a' && buffer1[k+3] == 'm' && buffer1[k+4] == 'e'){
                     if(buffer1[k+5] == '>'){
                         k= k +6;
                         while(buffer1[k] != '<' && buffer1[k+1] != '/'&& buffer1[k+6] != '>'){
                             //Serial.print(buffer1[k]);
                             readServer += buffer1[k];
                             k++;
                           }
                           Serial.println();
                     }  
                   }
                 }
                 k++;
             }
           //    FOR <message></message>
           k = 0;
           while(k<size1)
             {
                 if(buffer1[k] == '<'){
                   if(buffer1[k+1] == 'm' && buffer1[k+2] == 'e' && buffer1[k+3] == 's' && buffer1[k+4] == 's' && buffer1[k+5] == 'a' && buffer1[k+6] == 'g' && buffer1[k+7] == 'e'){
                     if(buffer1[k+8] == '>'){
                         k= k +9;
                         while(buffer1[k] != '<' && buffer1[k+1] != '/'&& buffer1[k+9] != '>'){
                             //Serial.print(buffer1[k]);
                             readServer += buffer1[k];
                             k++;
                           }
                           Serial.println();
                     }  
                   }
                 }
                 k++;
             }
           //    FOR <discount></discount>
           k = 0;
           while(k<size1)
             {
                 if(buffer1[k] == '<'){
                   if(buffer1[k+1] == 'd' && buffer1[k+2] == 'i' && buffer1[k+3] == 's' && buffer1[k+4] == 'c' && buffer1[k+5] == 'o' && buffer1[k+6] == 'u' && buffer1[k+7] == 'n' && buffer1[k+8] == 't'){
                     if(buffer1[k+9] == '>'){
                         k= k +10;
                         while(buffer1[k] != '<' && buffer1[k+1] != '/'&& buffer1[k+10] != '>'){
                             //Serial.print(buffer1[k]);
                             readServer1 += buffer1[k];
                             k++;
                           }
                           Serial.println();
                     }  
                   }
                 }
                 k++;
             }
         Serial.println("------------------------------------------------------");
         Serial.println(readServer);
         lcd.clear();
         lcd.setCursor(0,0);
         lcd.print(readServer);
         lcd.setCursor(0,1);
         lcd.print(readServer1);
         delay(5000);
         Serial.println("disconnecting...");
         client.stop();
         t = true;
     }
 }
}

  Serial.println("########################################");``Serial.println("------------------------------------------------------");
You seem very keen on pouring precious RAM down the drain, for no good reason.

Maybe you should tackle that first.

You've also got a lot of repeated code (look at "MainSet" and look at what you do if, for example, enter a '*','A', 'B','C','D' or '#' key.

If your code is shorter, it gives the bugs fewer dark corners to hide in.

have removed every kind of Serial.print from my sketch but still the code crashes.

have you fixed these too?

        client.println("POST /api/verify_khaba_test HTTP/1.0");

But the strings don't need to waste RAM, do they?

    client.println(F("POST /api/verify_khaba_test HTTP/1.0"));

i have placed F() to every

client.println

or to this

Serial.println

but still my code crashes or stops working on the second POST inside loop

OK, thanks for letting us know.
Good luck.

my code still crashes or stops in the loop where i am posting to server again
What can i do here?

You could allow/help someone here to help you. (hint)

Another hint: See reply #1

This is the updated code but my sketch stills stop/crashes in LOOP where i am trying to post again
My code is long so i have posted it in 2 replies

#include <Keypad.h>          // Include the Keypad library.
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>


const byte rows = 4;          // Define the amount of rows and columns for the keypad.
const byte cols = 4;

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
char server[] = "beta1.tossdown.com";
//char server[] = "tossdown.com";
IPAddress ip(192, 168, 5, 34);
EthernetClient client;

LiquidCrystal lcd(A1,A0,A5,A4,A3,A2);
char keys[rows][cols] = {      // Define the characters of the keypad.
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[rows] = {9,8,7,6};    // Define the pins connected to the keypad.
//byte colPins[cols] = {5,4,3,2};
byte colPins[cols] = {5,3,2,1};
//byte colPins[cols] = {5,12,11,10};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);      // Initialize the keypad.

void setup()
{
  Serial.begin(9600);
  Serial.println(F("in Setup"));
  MainSet();
  getNumber();
  clientConnect();
}

void loop()
{
  Serial.println(F("in Loop"));
  MainSet();
  getNumber();
  clientConnect();
}
//---------------------------------
int i = 0;
char* ourCode = "13467913";      // Set the required PIN code.
char* ourCode1 = "********";
char key;

void MainSet()
{
  i =0;
  ourCode1[0] = '*';ourCode1[1] = '*';ourCode1[2] = '*';ourCode1[3] = '*';ourCode1[4] = '*';ourCode1[5] = '*';ourCode1[6] = '*';ourCode1[7] = '*';
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print(F("Enter Card #"));
}

void getNumber()
{ 
    while(i!=8)
    {
      char key = keypad.getKey();      // Get the key press from the keypad.  
         //Serial.println(key);      
        if (int(key) !=0)
        {   
            if(key == '0' || key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9')
            { 
                lcd.setCursor(i,1);
                //lcd.print(ourCode1[i]);
                ourCode1[i] = key;
                lcd.print(ourCode1[i]);
                i++;
            }
            else if (key == '*')   // To clear Screen if wrong number/digit entered  
            {
                i=0;
                ourCode1[0] = '*';ourCode1[1] = '*';ourCode1[2] = '*';ourCode1[3] = '*';ourCode1[4] = '*';ourCode1[5] = '*';ourCode1[6] = '*';ourCode1[7] = '*';
                lcd.clear();
                MainSet();
            }
            else if (key == 'A' || key == 'B' || key == 'C' || key || 'D' || key == '#')
            {
                i=0;
                ourCode1[0] = '*';ourCode1[1] = '*';ourCode1[2] = '*';ourCode1[3] = '*';ourCode1[4] = '*';ourCode1[5] = '*';ourCode1[6] = '*';ourCode1[7] = '*';
                lcd.setCursor(0,2);
                lcd.print(F("Invalid Input"));
                delay(1000);
                lcd.clear();
                MainSet();
            }
        } 
    } i = 0;
}

This is the second part of my updated code

int size1=0;
char buffer1[200];
String readServer = "";
String readServer1 = "";
String readServer2 = "";
bool check = false;

void clientConnect()
{ 
    if (Ethernet.begin(mac) == 0) {
      Serial.println(F("Failed to configure Ethernet using DHCP"));
      // try to congifure using IP address instead of DHCP:
      Ethernet.begin(mac, ip);
    }
    
    Serial.println(F("connecting..."));
    // if you get a connection, report back via serial:
    
    if (client.connect(server, 80)) {
    
          Serial.println(F("connected"));
          // Make a HTTP request: 
          
            //String b = "rid=18&bid=18&khaba_card=24990435";
            String rid = "18";
            String bid = "18";
            String cardN = ourCode1;
            Serial.println(cardN); 
            String b = "";
            b = "rid="+rid;
            b +=  "&bid="+bid;
            b +=  "&khaba_card="+cardN;
            Serial.println(b); 
            client.println(F("POST /api/verify_khaba_test HTTP/1.0")); 
            //client.println("Host: tossdown.com");
            client.println(F("Host: beta1.tossdown.com")); 
            client.println(F("User-Agent: Arduino/1.0")); 
            client.println(F("Connection: close"));
            client.println(F("Content-Type: application/x-www-form-urlencoded")); 
            client.print(F("Content-Length: ")); 
            client.println(b.length()); 
            client.println(); 
            client.println(b);
      //      Serial.println("Sent data: " + b);
      //      client.println();
  } else {
        // if you didn't get a connection to the server:
        Serial.println(F("connection failed"));
     }

  bool t = false;

  while(t == false){
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) 
  {
        //Serial.println("client available");
        char c = client.read();
        //Serial.print(c);
        // Removing everything before the start and including of ?> 
        if (c == '?' && i == 0)
        {
          c = client.read();
          if(c == '>')
          {
            check = true; // check to start storeing next chracter if the last one was ?>
            i ++;
            c = client.read();
          }
        }
       //if(c == '\n' || c == ' ') // Removes new lines but space is not working
         // c = client.read();
            
        // Storing the strings of XML
        if(check == true)
        { 
          buffer1[size1] = c;
          //readServer += c;
          size1++;
        }
    }
       
        // if the server's disconnected, stop the client:
        if (!client.connected()) 
        {
            int k = 0;
              //    FOR <status></status>  
              k = 0;
              while(k<size1)
                {
                    if(buffer1[k] == '<'){
                      if(buffer1[k+1] == 's' && buffer1[k+2] == 't' && buffer1[k+3] == 'a' && buffer1[k+4] == 't' && buffer1[k+5] == 'u' && buffer1[k+6] == 's'){
                        if(buffer1[k+7] == '>'){
                            k= k +8;
                            while(buffer1[k] != '<' && buffer1[k+1] != '/'&& buffer1[k+8] != '>'){
                                //Serial.print(buffer1[k]);
                                //readServer += buffer1[k];
                                k++;
      
                              }
                        }  
                      }
                    }
                    k++;
                }
                //readServer += " ";
                k = 0;
                //    FOR <name></name>
              while(k<size1)
                {
                    if(buffer1[k] == '<'){
                      if(buffer1[k+1] == 'n' && buffer1[k+2] == 'a' && buffer1[k+3] == 'm' && buffer1[k+4] == 'e'){
                        if(buffer1[k+5] == '>'){
                            k= k +6;
                            while(buffer1[k] != '<' && buffer1[k+1] != '/'&& buffer1[k+6] != '>'){
                                //Serial.print(buffer1[k]);
                                readServer += buffer1[k];
                                k++;
                              }
                        }  
                      }
                    }
                    k++;
                }
              //    FOR <message></message>
              k = 0;
              while(k<size1)
                {
                    if(buffer1[k] == '<'){
                      if(buffer1[k+1] == 'm' && buffer1[k+2] == 'e' && buffer1[k+3] == 's' && buffer1[k+4] == 's' && buffer1[k+5] == 'a' && buffer1[k+6] == 'g' && buffer1[k+7] == 'e'){
                        if(buffer1[k+8] == '>'){
                            k= k +9;
                            while(buffer1[k] != '<' && buffer1[k+1] != '/'&& buffer1[k+9] != '>'){
                                //Serial.print(buffer1[k]);
                                readServer += buffer1[k];
                                k++;
                              }
                        }  
                      }
                    }
                    k++;
                }
              //    FOR <discount></discount>
              k = 0;
              while(k<size1)
                {
                    if(buffer1[k] == '<'){
                      if(buffer1[k+1] == 'd' && buffer1[k+2] == 'i' && buffer1[k+3] == 's' && buffer1[k+4] == 'c' && buffer1[k+5] == 'o' && buffer1[k+6] == 'u' && buffer1[k+7] == 'n' && buffer1[k+8] == 't'){
                        if(buffer1[k+9] == '>'){
                            k= k +10;
                            while(buffer1[k] != '<' && buffer1[k+1] != '/'&& buffer1[k+10] != '>'){
                                //Serial.print(buffer1[k]);
                                readServer1 += buffer1[k];
                                k++;
                              }
                        }  
                      }
                    }
                    k++;
                }
            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print(readServer);
            lcd.setCursor(0,1);
            lcd.print(readServer1);
            delay(5000);
            client.stop();
            t = true;
        }
    }
}

Your code is a bit light on useful, meaningful comments, but if I were you, I'd look at
a) Getting rid of "String"
b) Using sensible string handling functions like "strstr"
c) Stop repeating code (I think I've already mentioned this)
d) using the auto-format tool to make your code more legible.

How to use this forum

You can attach your code to a post. You don't have to split it into parts.