Jump to content

[SOLVED] mysql_real_escape_string


mdnghtblue

Recommended Posts

This is probably an easy fix, but I'm still new to this stuff.

 

I have a notice field in the database, and I save it like this:

 

if ($save_notice) {
swearCheck($notice);
$notice = htmlspecialchars(strip_tags($notice));
//$notice = addslashes($notice);
$notice = preg_replace("#([\S]{60})#i","\\1 ",$notice);
$notice = substr(ereg_replace("\n\n","\n",$notice),0,1500);
$users[notice] = $notice;
saveUserData($users,"notice");
echo "Notice Saved!<BR><b>Your Notice:</b> ".nl2br(htmlspecialchars_decode($notice))."<BR>";
}

 

 

in saveUserData, I use mysql_real_escape_string before updating the database:

 

$data = mysql_real_escape_string($data);
sqlQuotes($data);
$update .= "$tmp=\"$data\"";

 

 

But the notice shows up with "rn"s where a line break should be (and in the database too). This only started happening when I added in mysql_real_escape_string. Am I using it wrong? =/

Link to comment
https://forums.phpfreaks.com/topic/106185-solved-mysql_real_escape_string/
Share on other sites

That was the problem. =) It was stripslashing it. Commented it out and it was fine.

 

// replace ' with '' to avoid malformed SQL queries
function sqlQuotes (&$str)
{
$str = str_replace("'","''",stripslashes($str));
}

 

Do I even still need this function if I'm using mysql_real_escape_string?

 

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.