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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.