Form Method and SD Card

I am attempting to save some inputs onto an SD card through the internet.
However, when I use two inputs the SD card will not open, it will work with only one.
In the code below if I comment out either
client.print ("");"
or
client.print ("");
The SD card will open and the uncommitted input will save to the file.
Has anyone else experienced this issue?
I am at a loss of how to fix it.

Arduino Uno V3
Seeed Ethernet Sheild V2.0 (W5200)

#include <SD.h>
#include <SPI.h>
#include <EthernetV2_0.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);
#define W5200_CS  10
#define SDCARD_CS 4

//Login Information
char MyID[] = "123"; //Variable for Password
char MyPass[] = "123"; //Variable for Password
String buffer = "";  //  Declare the buffer variable
String NewBuffer = "";  //  Declare the buffer variable
int ValidID = 0;

//SD Card
File Login;
File Data;

//Analogue Ves
int buff[6];

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
  pinMode(W5200_CS, OUTPUT);
  //disconnect the W5200
  digitalWrite(W5200_CS,HIGH);
  pinMode(SDCARD_CS,OUTPUT);
  if (!SD.begin(SDCARD_CS)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  //start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  //Initialize Login Variable
  ValidID = 0;
}

void loop() {
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        //buffer+=c;
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          while(client.available()) {
            char UnPwrd = client.read();
            Serial.write(UnPwrd);
            buffer+=UnPwrd;
          }
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connnection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          if (ValidID == 0) {
            client.print ("<form method=post>");
            client.print ("User ID:");
            client.print ("
");
            client.print ("<input type=id name=id size=25>");
            client.print ("
");
            client.print ("Password:");
            client.print ("
");
            client.print ("<input type=pass name=pass size=25>");
            client.print ("
");
            client.print (" <input type=submit value=Login>");
            client.print ("</form>");                    
          }
          if(buffer.indexOf(MyPass)>=0 && buffer.indexOf(MyID)>=0) {
              ValidID = 1;
              client.print("<meta http-equiv=\"refresh\" content=\"0\">");
              buffer="";
          }    
          if (ValidID == 1)  {
            client.print ("<form method=post>");
            client.print ("New User ID:");
            client.print ("
");
            client.print ("<input type=newwid name=newid size=25>");
            client.print ("
");
            client.print ("New Password:");
            client.print ("
");
            client.print ("<input type=newpass name=newpass size=25>");
            client.print ("
");
            client.print (" <input type=submit value=Login>");
            client.print ("</form>");
            if(buffer != "") {
              Login = SD.open("Login.txt",FILE_WRITE);
              if (Login) {
              Serial.print(buffer);
              Login.println(buffer);
              Login.close();
              Serial.println("New ID Added");
              }
              else {
                //failed.
               Serial.println("Error Opening Login File");
              }
              ValidID = 2;
              client.print("<meta http-equiv=\"refresh\" content=\"0\">");
            }
          }
          if (ValidID == 2)  {
            client.println("<meta http-equiv=\"refresh\" content=\"5\">");
            for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
              client.print("analog input ");
              client.print(analogChannel);
              client.print(" is ");
              buff[analogChannel] = analogRead(analogChannel);
              client.print(buff[analogChannel]);
              client.println("
");
            }
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    delay(200);
    // close the connection:
    client.stop();
    buffer="";       //  Clear the buffer at end of line
    Serial.println("client disonnected");
    Serial.println("ValidID:");
    Serial.println(ValidID);
  }
}

Any assistance is greatly appreciated

I figured out the how to solve the issue.
If anyone is interested, do the following:
Move the SD card logic after the client.stop.
Also disconnect the W5200 before the SD card logic.
Lastly disconnect the SD card after the SD card logic.

The code below is not 100% the same but it works.

#include <SD.h>
#include <SPI.h>
#include <EthernetV2_0.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);
#define W5200_CS  10
#define SDCARD_CS 4

char MasterID[] = "username=321"; //Variable for Password
char MasterPass[] = "pass=123"; //Variable for Password
String buffer = "";  //  Declare the buffer variable
int ValidID = 0;

//SD Card
File LoginFile;
File DataFile;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin 
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output 
  // or the SD library functions will not work. 
  pinMode(W5200_CS, OUTPUT);
  //disconnect the W5200
  digitalWrite(W5200_CS,HIGH);
  pinMode(SDCARD_CS,OUTPUT);
  if (!SD.begin(SDCARD_CS)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
  //start the Ethernet connection and the server:
  digitalWrite(SDCARD_CS, HIGH);
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  //Initialize Login Variable
  ValidID = 0;
}

void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        //buffer+=c;
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          while(client.available()) {
            char IDPass = client.read();
            Serial.write(IDPass);
            buffer+=IDPass;
          }
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connnection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          if (ValidID == 0) {
            client.print ("<form method=post>");
            client.print ("User Name:");
            client.print ("
");
            client.print ("<input type=username name=username size=25>");
            client.print ("
");
            client.print ("Password:");
            client.print ("
");
            client.print ("<input type=password name=pass size=25>");
            client.print ("
");
            client.print (" <input type=submit value=Login>");
            client.print ("</form>");                    
            if (buffer.indexOf(MasterPass)>=0 && buffer.indexOf(MasterID)>=0) {
              ValidID = 1;
              Serial.println("Found ID");
              client.print("<meta http-equiv=\"refresh\" content=\"0\">");
              buffer="";
            }
          }
          if (ValidID == 1)  {
            client.print ("<form method=post>");
            client.print ("New User ID:");
            client.print ("
");
            client.print ("<input type=newwid name=newid size=25>");
            client.print ("
");
            client.print ("New Password:");
            client.print ("
");
            client.print ("<input type=newpass name=newpass size=25>");
            client.print ("
");
            client.print (" <input type=submit value=Login>");
            client.print ("</form>");
          }
          client.println("</html>");
          break;
         }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    delay(200);
    // close the connection:
    client.stop();
    //disconnect the W5200
    digitalWrite(W5200_CS,HIGH);
    if(buffer != "" && ValidID == 1) {
      LoginFile = SD.open("Login.txt",FILE_WRITE);
      if (LoginFile) {
      LoginFile.println(buffer);
      LoginFile.close();
      Serial.print("New ID Added");
      }
      else {
        Serial.print("Error Opening Login File");
      }
      ValidID = 2;
      client.print("<meta http-equiv=\"refresh\" content=\"0\">");
      //disconnect the SD card
      digitalWrite(SDCARD_CS,HIGH);
    }
    buffer="";       //  Clear the buffer at end of line
    Serial.println("client disonnected");
    Serial.println("ValidID:");
    Serial.println(ValidID);
  }
}