Ethernet Module+RFID+MySQL

Hello Everyone
I'm having trouble in combination of Ethernet Module,RFID reader and MySQL server.
Ethernet module can write data to MySQL server fine.Also RFID reader is reading data from cards fine.
But sometimes RFID freezes or Ethernet Module stops sending data.
And i don't know the reason.Because it's happening randomly not a same specific condition.
Its on Arduino Mega and RFID Ethernet Module sharing the same pins 50-52.
I'm controlling Ethernet module ENC28J60 using CS pin on the other side i'm controlling RC522 RFID using SDA pin(i'm not sure about it but someone on the forum mentioned to do this).
I included my code and php files used to communicate with MySQL.
Any advice will be approciated.

php_files.txt (592 Bytes)

eAttendance_v2.0.ino (4.81 KB)

  while (Serial1.available()) { // check for gps data
    if (gps.encode(Serial1.read())) { // encode gps data
      gps.get_position(&lat, &lon); // get latitude and longitude
      Serial.print("lat: ");
      Serial.print(lat);
      Serial.print("          ");
      Serial.print("lon: ");
      Serial.println(lon);
      if (digitalRead(40)==HIGH)
      {
        Serial.println("Message Sent!");
        sendmessage();
        //recievemessage(); // to receive message enable receivemessage function
        // and "//" the sendmessage function
      }
      if (SMS.available() > 0) { // verify any bits which income through pins 9 and 10
        Serial.write(SMS.read());// write income data on serial monitor
      }
    }

If there is serial data, and the character read completes a GPS sentence, check for incoming text messages.

I must be missing something.

  String message = "I'm lost this is my location: http://https://www.latlong.net/c/?lat=";

I can't believe that that is anything like a valid URL.

Your post mentions nothing about a GPS, that you actually read, but does mention an RFID reader, that you don't read.

Just what IS your problem?

Sorry uploaded wrong code.
I will change it.