Saving RFID data to database

Hello , good day how to convert this result to variable ?
I've tried Serial.Read to read the result but it's not working.
Please help me. thank you.

Convert what result?
Where is your code?

Here is my code,
i want to pass the value to variable

  #include <SPI.h>
   #include <MFRC522.h>
   #define RST_PIN         5           // Configurable, see typical pin layout above
   #define SS_PIN          53          // Configurable, see typical pin layout above
   MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
    // Number of known default keys (hard-coded)
    // NOTE: Synchronize the NR_KNOWN_KEYS define with the defaultKeys[] array
    #define NR_KNOWN_KEYS   8
    // Known keys, see: https://code.google.com/p/mfcuk/wiki/MifareClassicDefaultKeys
    byte knownKeys[NR_KNOWN_KEYS][MFRC522::MF_KEY_SIZE] =  {
    {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // FF FF FF FF FF FF = factory default
    {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5}, // A0 A1 A2 A3 A4 A5
    {0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5}, // B0 B1 B2 B3 B4 B5
    {0x4d, 0x3a, 0x99, 0xc3, 0x51, 0xdd}, // 4D 3A 99 C3 51 DD
    {0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a}, // 1A 98 2C 7E 45 9A
    {0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7}, // D3 F7 D3 F7 D3 F7
    {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, // AA BB CC DD EE FF
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}  // 00 00 00 00 00 00
    };
    /*
    * Initialize.
    */
    void setup() {
    Serial.begin(9600);         // Initialize serial communications with the PC
    while (!Serial);            // Do nothing if no serial port is opened (added for Arduinos based on 
    ATMEGA32U4)
    SPI.begin();                // Init SPI bus
    mfrc522.PCD_Init();         // Init MFRC522 card
   // Serial.println(F("Try the most used default keys to print block 0 of a MIFARE PICC."));
    }
    /*
    * Helper routine to dump a byte array as hex values to Serial.
    */
    void dump_byte_array(byte *buffer, byte bufferSize) {
    for (byte i = 0; i < bufferSize; i++) {
        Serial.print(buffer[i] < 0x10 ? " 0" : " ");
        Serial.print(buffer[i], HEX);
    }
    }
    /*
    * Try using the PICC (the tag/card) with the given key to access block 0.   
    * On success, it will show the key details, and dump the block data on Serial.
    *
    * @return true when the given key worked, false otherwise.
    */
    boolean try_key(MFRC522::MIFARE_Key *key)
    {
    boolean result = false;
    byte buffer[18];
    byte block = 0;
    byte status;
    // Serial.println(F("Authenticating using key A..."));
    status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, key, &
    (mfrc522.uid));
    if (status != MFRC522::STATUS_OK) {
     // Serial.print(F("PCD_Authenticate() failed: "));
    // Serial.println(mfrc522.GetStatusCodeName(status));
    return false;
    }
    // Read block
    byte byteCount = sizeof(buffer);
    status = mfrc522.MIFARE_Read(block, buffer, &byteCount);
    if (status != MFRC522::STATUS_OK) {
    // Serial.print(F("MIFARE_Read() failed: "));
    // Serial.println(mfrc522.GetStatusCodeName(status));
    }
    else {
    // Successful read
    result = true;
    //Serial.print(F("Success with key:"));
    dump_byte_array((*key).keyByte, MFRC522::MF_KEY_SIZE);
    //Serial.println();
    // Dump block data
    // Serial.print(F("Block ")); Serial.print(block); Serial.print(F(":"));
    dump_byte_array(buffer, 16);
    //Serial.println();
    }
    //  Serial.println();
    mfrc522.PICC_HaltA();       // Halt PICC
    mfrc522.PCD_StopCrypto1();  // Stop encryption on PCD
    return result;
    }
    /*
    * Main loop.
    */
    void loop() {
    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent())
        return;
    // Select one of the cards
     if ( ! mfrc522.PICC_ReadCardSerial())
     return;
     // Show some details of the PICC (that is: the tag/card)
     // Serial.print(F("Card UID:"));
     dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
     delay(3000);
     Serial.println();
     // Serial.print(F("PICC type: "));
     //  byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
     //Serial.println(mfrc522.PICC_GetTypeName(piccType));
     // Try the known default keys
     }

The forum software has turned your array indices to italics, so you need to go back and edit your post to add code tags.

Also, what does " but it's not working. " mean?

When i tapped the rfid , the result show up in these format:

15 3B 19 89

but i want these result turned into variable

They were in a variable, and you printed that variable out.

I can't see there is a problem here.

Because i need to store it to a variable to save it to database.

I don't know how to say this in another way, but if you printed it, then it must have been in a variable.

If you want to pack it into a single uint32_t, use either a C union (may have endianess issues) or use bit shifts (<<24, <<16, <<8 ) and OR operations, but make sure you cast the components to uint32_t first.

Is there any way to store the result in the database? sorry if i misunderstands you
because what i want to do is when i tapped the RFID the

15 3B 19 89

result will be automatically saved to database.

OK, you're not understanding me, because you haven't edited your earlier post and put in the code tags, and I'm not understanding you because I've told you what you need to do, and you've just repeated your earlier post, just a bit longer.

Sorry i'm so very confused about the RFID. but is there any way to saved it?

LesleyJay:
Sorry i'm so very confused about the RFID. but is there any way to saved it?

Yes, there is a way to save it, but you need to decide what it is you want to save and where you want to save it, whatever "it" turns out to be.

CtrlAltElite:
Yes, there is a way to save it, but you need to decide what it is you want to save and where you want to save it, whatever "it" turns out to be.

Ok sir,
What i want to save is the result of the RFID.
Where i want to save it to database.
that's what i want sir.

OK, first thing, cut out the "sir". Straight out. It looks phoney.

What do you mean by "the result of the RFID" ? Please use simple terms, because I am a simple person.

Which database do you want to save it to? Were does the database reside?

Second thing GO BACK AND EDIT YOUR POST WITH THE CODE, SO THAT PEOPLE CAN READ IT

CtrlAltElite:
OK, first thing, cut out the "sir". Straight out. It looks phoney.

What do you mean by "the result of the RFID" ? Please use simple terms, because I am a simple person.

Which database do you want to save it to? Were does the database reside?

When i tap the rfid , this result shows:
15 3B 19 89
i want to save it to database
Mysql database.

Looking at this little piece in your code

dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);

I suspect that mfrc.uid.uidByte contains your key of interest.

So you can use that directly; no need to store in a variable.

If you want to copy it to a variable, you will have to indicate where in your code you need it.

Please edit your post with the code; place

[code]before the code and [/code]

after the code. This is meant by 'use of code tags' and your code will be formatted in a window as show above and will not be mangled by the forum software.

Note
No experience with mfrc.

PS written before you posted your last post.

And this MySQL runs on the Arduino?
What methods do you have to write data to the database?
Do those methods include simple byte arrays?
Do you want to save the binary of the RFID data, or the ASCII hex representation (which is what you printed) ?

I'm sorry, but I don't see your problem - you have data, and you have a database.
What is stopping you writing to the database?

sterretje:
Looking at this little piece in your code

dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);

I suspect that mfrc.uid.uidByte contains your key of interest.

So you can use that directly; no need to store in a variable.

If you want to copy it to a variable, you will have to indicate where in your code you need it.

Please edit your post with the code; place

[code]before the code and [/code]

after the code. This is meant by 'use of code tags' and your code will be formatted in a window as show above and will not be mangled by the forum software.

Note
No experience with mfrc.

PS written before you posted your last post.

I can't use the dump_byte to my conditional statement to check if the result of the rfid is the same.

I understand that you can't use it in a conditional staterment. What I was saying is that the bytes that your interested in are in the variable mfrc522.uid.uidByte and that variable contains mfrc522.uid.size bytes.

You can send those bytes directly to the database if the field in the db is a binary field or you can convert to text first and send that to the db.

Looking at the result 15 3B 19 89 in reply #4, your tag contains 4 bytes. What do you want to compare them with?

sterretje:
I understand that you can't use it in a conditional staterment. What I was saying is that the bytes that your interested in are in the variable mfrc522.uid.uidByte and that variable contains mfrc522.uid.size bytes.

You can send those bytes directly to the database if the field in the db is a binary field or you can convert to text first and send that to the db.

Looking at the result 15 3B 19 89 in reply #4, your tag contains 4 bytes. What do you want to compare them with?

Hello, the result from reply #4 is the result everytime i tap the rfid.
I tried this code but still, no success:

 if (strncmp(mfrc522.uid.uidByte, "D4 39 F8 BE", mfrc522.uid.size) == 1) {
      Serial.println("Card found");
}

The D4 39 F8 BE is one of the result when i tap the rfid.