Jump to content

My PHP script is letting HTML injections, how do i prevent it?


angel1987

Recommended Posts

Here is the code that i am using to accept data and display the data.

 

To accept and add it in database i am using :

$comment = $_POST['txtcomment'];
$comment = @mysql_real_escape_string($comment);

 

To display the data from DB i am using :

$comment = $rowscomment['comment'];
<?php echo nl2br($comment); ?>

 

Please help me correct it....... I am still learning PHP.

 

 

Thanks for the answers,

htmlspecialchars()

worked.

 

But is there anything else that i need to know? Just as an information to prevent issues related to other special characters that might be used for HTML or SQL injections or just to mess with the applications?

 

I need the script to function perfectly, so is there anything i need to add while adding or displaying the data? Thanks again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.