Go Back   SitePoint Forums > Forum Index > Program Your Site > PHP
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Nov 8, 2009, 13:58   #1
Floezen
SitePoint Addict
 
Join Date: Feb 2003
Location: Berlin
Posts: 315
Unable to insert base64_decode data in mySQL

Hi,

I am having a very strange problem: I have a field in my db where I store to content of emails base64_encoded.
When I read this table and decode the content I can echo it "human readable", but if I try to update the table with exact the same content it stays encoded...

The second strange thing is, that this applies to around 80% of the rows, but not all.

Here is the code:

PHP Code:

$get_decoded_body_data = mysql_query("select id, content from ".$prefix."_bounced_mails", $dbi);

while(list(
$decoded_id, $decoded_body_data)=mysql_fetch_row($get_decoded_body_data)) {
//decode  $decoded_body_data
$new_content = base64_decode($decoded_body_data);
//Echo readable text
echo $new_content<br />";
//Insert readable text into db
mysql_query ("
update ".$prefix."_bounced_mails set content='$new_content' WHERE id='$decoded_id'", $dbi);
}
Encoded rows which start with "SGkuIFRoa" will stay encoded, others are readable after the update.

Notice: When echoing $new_content everything is decoded!

I really don't have a clue what's going on. Please help!

Regards
Florian
Floezen is offline   Reply With Quote
Old Nov 8, 2009, 14:19   #2
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 464
ever heard of mysql_real_escape_string()?
Shrapnel_N5 is offline   Reply With Quote
Old Nov 10, 2009, 11:42   #3
Floezen
SitePoint Addict
 
Join Date: Feb 2003
Location: Berlin
Posts: 315
apparently not...

Thanx for that tip!
Floezen is offline   Reply With Quote
Old Nov 10, 2009, 12:01   #4
Shrapnel_N5
SitePoint Evangelist
 
Shrapnel_N5's Avatar
 
Join Date: Oct 2009
Posts: 464
must be used every time you place data into query.
wonder, how lived without id before
Shrapnel_N5 is offline   Reply With Quote
Old Nov 10, 2009, 16:20   #5
cranial-bore
SitePoint Wizard
 
cranial-bore's Avatar
 
Join Date: Jan 2002
Location: Australia
Posts: 2,092
To be clear Floezen, you should be escaping data used in a query whenever it may have come from a user (GET, POST, COOKIE), or another external source, or even your own data if it could contain funky characters.
cranial-bore is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 20:22.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved