My PHP site doesn't show the paragraphs of my database texts

Discussion in 'PHP' started by indiodoido, May 5, 2006.

  1. #1
    Hi
    I’ve just developed a php page that gets texts from a mysql database and displays them on the site, but my problem is that it doesn’t show the paragraphs I make.
    The texts are uploaded to the database with a form.

    Can anyone help me?
     
    indiodoido, May 5, 2006 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Can you post the code you are refering to?

    Do you mean that the data is not in the mysql database, or the data is not making it back to the site from the database?
     
    jestep, May 5, 2006 IP
  3. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #3
    First thing to check: are you sure that you're converting your newline characters to '<br />'s?

    You're possibly just printing the string out and HTML is ignoring your new lines...
     
    TwistMyArm, May 5, 2006 IP
  4. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Simular to TwistMyArm

    When adding information to a database, new lines should be shown using "\n" (which you can not see, but there will be a new line)

    What you need to do on echo is a little function

    function ShowStr($str){
    $str = stripslashes($str);
    $str = str_replace("\n","<br>",$str);

    return $str;
    }

    Then everytime you echo a Blog from the mysql, just use that function name
     
    onlyican.com, May 5, 2006 IP
  5. Fl1p

    Fl1p Active Member

    Messages:
    511
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #5
    You can also use PHP's nl2br() function

    You do this when your inserting the content into your database, something like below...

    
    <?php
    
    $var = $_POST['textarea_name'];
    $var = nl2br($var);
    
    //Your MySQL queries here
    
    ?>
    
    Code (markup):
    More information on this function
    http://ca.php.net/manual/en/function.nl2br.php
     
    Fl1p, May 5, 2006 IP
  6. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    True, I am in a habit or creating my own functions.

    Couple of Tips

    Never insert HTM code into a MySQL DB
    and always, always run
    mysql_real_escape_string BEFORE adding anything to your database.
     
    onlyican.com, May 5, 2006 IP
  7. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Something else,

    I love php

    Find out Everyones Location

    I am es.php.net
    (Yes i know you can change it in the options)
     
    onlyican.com, May 5, 2006 IP