Help - simple question about my comments/review script

Discussion in 'PHP' started by edual200, May 18, 2009.

  1. #1
    when a user leaves a comment , say a long comment normally youd hit enter button a couple of times to create a new paragraph. on my comment script even after doing that all the text gets stuck together with no breaks, how to fix that?

    i did not include my comment script because it seems like its not needed just something i must be missing. if i do need to post it let me know
     
    edual200, May 18, 2009 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    create a unique id for that comment then write a script that tells whether that unique id is existing in the database or not.
     
    bartolay13, May 18, 2009 IP
  3. edual200

    edual200 Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    i dont think your answer has anything to do with my question.

    what i mean is comments submitted on my site dont contain any line breaks in between paragraphs of that comment.


    For example i type free then press enter then type free agin then press enter then type free again

    the out put should be like
    Free
    Free
    Free


    but the output that comes out is
    Free Free Free

     
    edual200, May 18, 2009 IP
  4. hassanahmad2

    hassanahmad2 Active Member

    Messages:
    243
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    60
    #4
    i think you should use the function nl2br() to convert line breaks (\n) to html <br>
     
    hassanahmad2, May 19, 2009 IP
  5. Arionix

    Arionix Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Arionix, May 19, 2009 IP
  6. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Example code you should use:

    
    function Escape($Data) { return mysql_real_escape_string($Data); }
    
    $Comment=Escape($_POST['comment']);
    $UserID=Escape($_POST['userid']);
    
    
    PHP:
    That is a very basic example, but if you would like more help, simply post the script and we can help secure it.
     
    NatalicWolf, May 19, 2009 IP
  7. NateJ

    NateJ Active Member

    Messages:
    240
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #7
    I've had this problem myself before, i simply did this:

    
    function replace($txt) {
    
    $txt = str_replace(array("\r\n", "\n", "\r"), '<br>', $txt); 
    
    return $txt;
    }
    PHP:
    Then, Where you're echoing put this:

    echo "".replace(FreeFreeFree)."";
    PHP:
    The output of this will be:

    Free
    Free
    Free


    Hope this helps.
     
    NateJ, May 19, 2009 IP
  8. edual200

    edual200 Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #8
    thanks everyone for your reply's, still i guess the 1 problem is that the comments are stored without the \r\n or \n or \r or whatever, there getting stored exactly as there written.

    Could it be that the table column is of type text ?
     
    edual200, May 19, 2009 IP
  9. edual200

    edual200 Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #9
    <form method=post action='comment.php' name='form'>Name
    <input type=text name=name size=30>
    Rating
    <select name="vote">
    <option value="5">(5 Stars) Best</option>
    <option value="4">(4 Stars) Better</option>
    <option value="3">(3 Stars) Good</option>
    <option value="2">(2 Stars) Fair</option>
    <option value="1">(1 Stars) Poor</option>
    </select>
    <textarea name=comments rows=7 cols=60></textarea><input onclick='DoSubmit ()' type='button' value='Submit Review'></form>


    Basically this is all the script, then comment.php uses the GET and insert into mysql
     
    edual200, May 19, 2009 IP
  10. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Correction to that, they ARE...\r\n is actually \x10\x13 or...enter key...it is not an HTML character, meaning...it does not show up as such. If you were to use "SELECT" and use nl2br it would then turn the enter key to <br> instead...Thus fixing the issue. I am available via instant messenger if needed.

     
    NatalicWolf, May 19, 2009 IP
    edual200 likes this.
  11. edual200

    edual200 Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #11
    that fixed it, needed nl2br.... Thank you very much, adding rep, also if youd like pm me your paypal and i will send $5 over, i know its not much :rolleyes:

    if you are a programmer for hire maybe even send your messaging details

     
    edual200, May 19, 2009 IP