Hi am making a control panel for an user to input some info on a textarea input field and putting the data in a mysql table.

I need to replace the enter stroke with <br><br> so when i display it i would show up properly.

obviusly the input is via html form <textarea> and am saving to mysql using PHP

$goodtext=str_replace("\"","&quot;",$rawtext);

In this example am replacing the " character to avoid any mysql errors, i guess it's something like this right?

    ...[man]nl2br[/man]?
    I mean save it in MySQL like it is and when you need to display it use this function...

      What bodzan said, but I want to emphasize that you better save the textarea data as it is. Then when you want it display, apply the nl2br around it.

      If you fix it upon insert, that will cause you trouble later on when you want to alter your data.

        Thanks that worked just fine 😉

        Another question if i may:

        I have a form to insert data into a mysql table, but when i want to show it how can i know if the value of one field is empy so i could skip it in the display? I try:

        if ($link != ""){ // i think this tells me that the value $link has some data
        echo "<a href=$link><img src=image.jpg></a>"; // show image with link
        } else {
        echo "<img src=image.jpg>"; // show image without link
        }

        But it didn't seem to work

          looks arite to me, except for a bit of formatting perhaps... Id have done

          if ($link != "") {   // if $link doesnt equal nothing
             echo ("<a href='$link'><img src='image.jpg'></a>"); // show image with link
          } else {
          echo ("<img src='image.jpg'>"); // show image without link
          }
          

          Elaborate on "didnt work"?

            Write a Reply...