Page 1 of 1

Insert html tags into sql database

Posted: Fri Feb 27, 2009 1:20 pm
by sacristoco
Hello!

I'm having a problem and I don't know if it has a solution...

I want to insert some html code into a sql database with php...

Something like this:

Code: Select all

mysql_query("INSERT INTO site_imagens (id_apoio, seccao, sumario) VALUES ('$ida', 2, '<font size='5'><img 
title='Florestas' alt='Florestas' src='florestas.jpg'/>Florestas</font>')");
The thing is that nothing happens... I have other querys along with this one, but they don't have the tags or ' and everything goes well... Does this has a solution? Is there other way to place ' in the database?

Thank you,
Alexandre

Re: Insert html tags into sql database

Posted: Fri Feb 27, 2009 1:57 pm
by mfrank410
I safe way is to base64 encode the strings that contain HTML tags.

Code: Select all

 
$encString = base64_encode( $origString ) ;
 
To decode the string use:

Code: Select all

 
$decString = base64_decode( $encString ) ;
 

Re: Insert html tags into sql database

Posted: Fri Feb 27, 2009 2:02 pm
by Benjamin
I wouldn't recommend using base64_encode as this will increase the storage requirements. Simply using mysql_real_escape_string would suffice.