Problem in strings / char variable

Hi all

I can not send data to the database, I have a problem with the variable rfidUid it sends me a strange character instead of the read number? I'm still learning, so do you have any idea where I made a mistake ?

please help :confused:

String rfidUid = "";   
char sqlbuf[128];


----------------------------------------------
//in void loop


 if (sqlconnect==true)
  {

       for (byte i = 0; i < mfrc522.uid.size; i++) 

                {
                rfidUid += String(mfrc522.uid.uidByte[i] < 0x10 ? "" : "");
               rfidUid += String(mfrc522.uid.uidByte[i], HEX);
              
                
          
                }
                

         Serial.println("Rfid Card verification...."); 

       sprintf(sqlbuf, "INSERT INTO RFID (idnumber) values ('%s')",&rfidUid) ;

         my_conn.cmd_query(sqlbuf);

         Serial.println("adding card record:  " + rfidUid);

   }

incorrect value : ?

correct value : 6ed5ded5

thx for help...

do you have any idea where I made a mistake ?

You did not put your code in code tags so much of your message is in italics
You only posted a snippet of code
You did not post a sample of the correct and incorrect values
You are using String objects where C style strings (zero terminated arrays of chars) are more appropriate

sprintf(sqlbuf, "INSERT INTO RFID (idnumber) values ('%s')",&rfidUid) ;

I don't think you need that & sign on &rfidUid, because now you are passing the address of that variable and I think you want the value held by rfidUid instead.

Printing the address of your String object as a string is a real error.
As you are using sprintf, let this function do the conversion

  sprintf(sqlbuf, "INSERT INTO RFID (idnumber) values ('%02x%02x%02x%02x')",
    mfrc522.uid.uidByte[0], mfrc522.uid.uidByte[1], mfrc522.uid.uidByte[2], mfrc522.uid.uidByte[3]);

Whandall:
Printing the address of your String object as a string is a real error.
As you are using sprintf, let this function do the conversion

  sprintf(sqlbuf, "INSERT INTO RFID (idnumber) values ('%02x%02x%02x%02x')",

mfrc522.uid.uidByte[0], mfrc522.uid.uidByte[1], mfrc522.uid.uidByte[2], mfrc522.uid.uidByte[3]);

Yes,thx You have right it is perfect solution.

thx so much :wink: