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)

Software serial on a Mega. Is that necessary or can you use another hardware serial port ?

Does a restart of the Mega cure the problem (at least temporarily) or do you have to restart your router, database server etc. ?

You are using Strings which can cause heap fragmentation on AVR devices. Character arrays are safer.

If you must use Strings, look at the reserve method to minimise storage fragmentation.

Thanks for your advice. :slight_smile:
Between what do you mean by Software Serial?
I only used serial to communicate with PC.
And mostly when trouble occurs i restart Arduino and mostly it fixes the problem.

Hordeous:
. . . what do you mean by Software Serial?
I only used serial to communicate with PC.
. . .

This, an extract from the program you attached, is software serial :

#include <SoftwareSerial.h>
. . .
SoftwareSerial SMS(9, 10);// rx(9) and tx(10)
. . .
SMS.begin(9600);       
. . .

The Arduino Mega has 4 serial ports, one of which could be used instead : Serial - Arduino Reference

If the problem "goes away" when you restart the Mega, the problem is likely to be your use of the String class. It may get better is you define message, limiter, lattitude, longditude and middle as global variables and reserve space for them with the reserve method of the String class. reserve() - Arduino Reference
Alternatively, use char arrays in place of Strings.

Ohh sorry looks like i uploaded wrong code between.
I will change it.

@Hideous - STOP cross-posting. This is the THIRD place I found your same inept post.