Jump to content

Secure MySQL queries


Welling

Recommended Posts

Now, I'm ussing this function to escape the variables I use in MySQL queries:

function escape($texto) {
$texto = trim($texto) ;
$texto = htmlspecialchars($texto) ;
return $texto ;
}

And It seems it works well (If it isn't secure, say me, please!).

The problem is when I want to insert HTML code in the DB, I have tried with mysql_real_escape_string() but " and ' are \" and \' when I show the html later and I must do something like:

$html = str_replace("\\'", "'", $html);
$html = str_replace("\\\"", "\"", $html);

But I think this shouldn't be the best way to do it. What do you think? any other way to do it?

Link to comment
https://forums.phpfreaks.com/topic/137851-secure-mysql-queries/
Share on other sites

inserting into a database.. you should always make sure to use mysql_real_escape_string.. ' and " are used by malicious users for an attack known as SQL Injection..

 

to remove the slashes later..

 

stripslashes() will do the trick

Link to comment
https://forums.phpfreaks.com/topic/137851-secure-mysql-queries/#findComment-720453
Share on other sites

I have tried to do stripslashes() before mysql_real_escape_string() and now, I don't need stripslashes() later to show the result because the \ aren't in the DB.

Is this because magick quotes are on and without magick quotes people don't need to use stripslashes() never?

Link to comment
https://forums.phpfreaks.com/topic/137851-secure-mysql-queries/#findComment-720700
Share on other sites

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.