Jump to content

mysql_real_escape_string help


SoireeExtreme

Recommended Posts

Ok, I'm saving html and text from a text area to the database.

Heres the code.

 

The Text Area

     print "<center>Headline:<br><textarea name='headline' rows='1' cols='60'>$userstats3[headline]</textarea><br></center>";

 

Save to database

    if(isset($_POST['submit']))
    {

$headline=mysql_real_escape_string(str_replace("\r\n","<BR>",$_POST['headline']));

      $SQL = "update d_users set headline='$headline' where username='$userstats3[username]'"; 
      mysql_query($SQL) or die("could not register");

 

Now my problem is when I save it. \r\n doesn't turn into the < br > as it should. From what I know is that its stripping it? Why is that? Any help would be greatly appreciated. Thanks in advance.

 

Oh I almost forgot to meantion. When I remove the \\ from the rn it will save it like I want to. But there is a problem that is created with that then. The problem with that is there are words with rn together in them and it will do the same thing to those words which I don't want to happen.

 

Also to add, I get this problem when I try to hit enter to make a new line when saving the the information from the textfield.

 

If anymore info is needed please let me know. Thanks again.

Link to comment
Share on other sites

Try printing out this:

 

print urlencode($_POST['headline']);

 

\r will show up as %0d, and \n will show up as %0a.  Then check to see if it's what you expect.

 

You might want to look at nl2br() as well.  You can always strip out the \n and \r after using nl2br().

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.