Jump to content

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?

 

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.