Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't write encrypted data

Status
Not open for further replies.

dmg2206

MIS
Feb 15, 2002
54
US
I'm trying to write a PHP script for encrypting data and saving it to a MySQL database. I've tested the script, and it can encrypt and decrypt just fine. However, when I actually try to post the data to the database, much of it gets truncated.

The SQL query that gets posted:

Code:
INSERT INTO `event_payments` (`id`, `ccnum`, `status`) VALUES (MD5(3), 'N¦0¤í?ñHŸY?\ZIJo¡9D%$~1t¿0øC?Bð|ž}OOÅ/›;ƒ¼ý?›@Ám%AÆ¡¢', 'Submitted')

And what gets posted to the ccnum column:

Code:
N

The id and status columns are filled as they should be. Any ideas?
 
what is the type of field your trying to insert it into? Is it varchar(1)??
 
The encryption process might produce a byte that contains #0. I would guess that MySQL would truncate the string at this point.

So I think you need to define your ccnum column as
Code:
VARCHAR(16) BINARY
or possibly as a BLOB field.

However, I haven't tested this out.

Andrew
Hampshire, UK
 
It's not the MD5'ed string that's been giving me problems. It's the next string, the long one that begins with "N" and includes the unicode characters.

Anyway, I've played around with column types and collations and finally found something that will let me write the string to the database preserving it as is. I've changed the column to MEDIUMBLOB.

Code:
 ALTER TABLE `table_name` CHANGE `ccnum` `ccnum` MEDIUMBLOB NOT NULL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top