Unable to insert Long Encrypted text in MYSQL through PHP???

if(!mysql_query("INSERT INTO voter(encrypt) VALUES('$encrypted')",$con)) { echo "not executed<br>" . mysql_error(); }
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘?~M?x???~L=??\nn?E zR?S?R?]}?/sG?WG?x??G?5T6?%??M??O??? ???V? W?!’ at line 1

$encrypted is about 5000 chararcters…and the data type of encrypt is Longtext.

The Value of $encrypted is:
?kpt%?pg? z?-?0#;f@$???Kv?8?!?>?3C???Qv???f)?,????e?????^+7??i?P???Z?W??y.??r???$??y?x???&???a ?!?[c???iH5???K?A??u??L?gz?lY-??1E+??69???K!???UCQ? ?E?g???hp/>2y??)???D???y ??u 8??e?:Jf]?w?(??e??>???,???#??d???-f? hSl?2B?ri=k???q???L?A$&2<??j ?4?fxa??q6{{?Y?t.???H???c&?]Z? ?`?$iH?\E??-*^??{???Z???3??~c???] w?Y&{?5?/?v?L????K H?@#?<???%f?_-??"?nP0IM??L?} N?g??2m2?2)?<?-U?Q|s??I±1??^6? ?C?o?n?m?t"}u?z~??|-?R?q??U$|G?Ty|K?????? T?’?~M?x???~L=??\nn?E zR?S?R?]}?/sG?WG?x??G?5T6?%??M??O??? ???V? W?!????2??E?? ???1??.? ? ??? ??s?5??_?..

Go into PHPMyAdmin, edit the table format, and change the field encrypt type to TEXT (doesn’t need a length value)

This should fix the problem. You will also want to do the query as such:

[php]
if(!mysql_query(“INSERT INTO voter(encrypt) VALUES(’”.addslashes($encrypted)."’);",$con))
{
echo “not executed
” . mysql_error();
}
[/php]

addslashes() makes it so that special characters (NULL bytes, single quotes, double quotes and backslashes) are escaped and can be entered into the database. Is you can see $encrypted has some of these and as such they themselves will return the error you mentioned. Let me know if this code works.

In all actuality TEXT/LONGTEXT would be the wrong datatype for binary (Yes, encrypted text usually outputs a binary block) Use BLOB for binary fields. I wouldnt use addslashes as well, use mysql_escape_string, which will format your data properly for insertion (remember to still add the quotes)

He never said anything about it being binary so I have no idea where you got that. All he said was he wanted to store a long string into the database, and the string contains special characters.

mysql_real_escape_string() and addslashes() in this case will do the exact same, though the PHP manual does say that the mysql_real_escape_string is more recommended.

Sponsor our Newsletter | Privacy Policy | Terms of Service