Insert html tags into sql database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sacristoco
Forum Newbie
Posts: 1
Joined: Fri Feb 27, 2009 1:15 pm

Insert html tags into sql database

Post 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
User avatar
mfrank410
Forum Newbie
Posts: 4
Joined: Fri Feb 27, 2009 1:45 pm
Location: Toronto, Canada

Re: Insert html tags into sql database

Post 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 ) ;
 
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Insert html tags into sql database

Post by Benjamin »

I wouldn't recommend using base64_encode as this will increase the storage requirements. Simply using mysql_real_escape_string would suffice.
Post Reply