views:

41

answers:

1

Hi all,

Am running a sql query with php to retrieve some data from mysql database. Everything works well except that, if the data contains symbols like < and >, then whatever data present between these symbols doesnt show in the output.

for example, if the data is something like "<hello there> how are you?" then only "how are you?" is shown.

But when i run the query directly, it shows me everything without missing anything.

I have done this before, but I cannot remember on the top of my head as what exactly I did. And google is not helping me today, slow day for me.... :(

+3  A: 

You should escape your databse response properly using htmlentities().

$sql = 'SELECT row_with_text FROM your_table';
$query = mysql_query($sql);
$result = mysql_fetch_array($query);
echo htmlentities($result['row_with_text']);

phpMyAdmin does the escaping for you, but it's your responsibility to escape text for HTML in your application.

Lekensteyn
That was awesome....... thanks Lekensteyn
tecks