Jump to content

mysql_real_escape_string breaking \n


Nolongerused3921

Recommended Posts

[quote]
Fixed's 'should''' be ''' workingrnrnrnrnYAY!
[/quote]

Was inserted as
[quote]
Fixed's 'should''' be ''' working



YAY!
[/quote]
Or something similar... I had just fixed my $_POST import function (To parse it all before a user has access to it), and it turns out it wasn't calling mysql_real_escape_string, so I added it and now er... It seems to have broken the ability for new lines to work.

Portion of the $_POST import function (The only part of it that pertains to this, the entire function is over 70 lines)
[code]
<?php
if (get_magic_quotes_gpc()) {
$tmp_data = stripslashes($tmp_data);
}
if ($filter_type == 2) {
$tmp_data = htmlentities($tmp_data);
$tmp_data = mysql_real_escape_string(strip_tags(trim($tmp_data)));
} elseif (!is_numeric($tmp_data)) {
//Then we can finish this.. otherwise it should be safe if it's just a number..
$tmp_data = htmlspecialchars($tmp_data, ENT_QUOTES);
$tmp_data = mysql_real_escape_string(strip_tags(trim($tmp_data)));
}
?>
[/code]

My content/bbcode parsing (The part that is called in order to strip slashes, convert nl2br, convert bbcode, etc.):
[code]
<?php
    function bbcode($data, $bbcode_on = TRUE){
    $db = $this->db_class;
        if ($db->is_connected() == NOT_CONNECTED){
            $db->connect();
        }

        $data = htmlspecialchars($data);
$data = stripslashes($data);
$pattern = array();
$replacement = array();
$bbcode = $GLOBALS['bbcode'];
if ($bbcode_on = TRUE) {
for ($i = 0; $i != count($bbcode); $i++) {
if ($bbcode[$i][type] == "bbcode") {
array_push($pattern,$bbcode[$i][pattern]);
array_push($replacement,$bbcode[$i][replacement]);
}
if ($bbcode[$i][type] == "smiley") {
$data = str_replace($bbcode[$i][pattern], "<img src='".$this->rdir."images/smilies/".$bbcode[$i][replacement]."' />", $data);
}
}
$data = preg_replace($pattern, $replacement, $data);
        }

        $data = str_ireplace(chr(10), "<br />\n", $data);
        nl2br($data);
        return $data;
    }

function content($data, $bbcode_on = TRUE) {
$data = html_entity_decode($data);
$data = $this->bbcode($data, $bbcode_on);
return $data;
}
?>
[/code]

All content is sent through content($data, TRUE/FALSE), and this is what is [b]now[/b] screwing it up, but prior to adding real_mysql_escape_string, it was working fine.
Link to comment
Share on other sites

Yes it was a typo in the post... Too bad, I thought it was that simple :(

And this may help a bit... The data from MySQL (Unedited, directly from phpmyadmin) :
[quote]
Wonder\r\n\r\n\r\n\r\n\r\n\r\nIf\r\n\r\n\r\nTHis\r\nREALLY\r\n\r\n\r\nWORKS\r\n\r\n!?
[/quote]
(I wrote a new string to just test this and not stripping \')

The html from the edit area:
[code]
<textarea name="content" cols="80" rows="20">Fixed \r\n\r\nit\r\n\r\nshould\r\n\r\n\r\n\r\nwork\r\n\r\n\r\n\r\n\r\nNOW!</textarea>
[/code]

From just printing the item:
[code]
Fixed \r\n\r\nit\r\n\r\nshould\r\n\r\n\r\n\r\nwork\r\n\r\n\r\n\r\n\r\nNOW!
[/code]

The code to print it:
[code=php:0]
<?php print $parser->content($temp_data[content]); ?>
[/code]
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.