Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2012
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Retrieve value from database (with same layout for textarea)

    Hi,

    I have a textarea box for user to enter the address.

    For example, user entered the following format:
    100 ABC Road
    #01-00
    Country code 450505


    I am able to capture the above data into the database and I am also able to retrieve it from the database. However, when i display it will show in 1 line.

    100 ABC Road #01-00 Country code 450505

    Can someone kindly advice, how to display the same layout as what user enter in textarea box?

    Thanks.

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    how is the database entry formated?

    eg what is your insert script?
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    On top of this, what are you using to show it? If you put it back into a <textarea> does it show with linefeed? HTML does not render \n as a line break. If \n is available within the string, you can use nl2br to put it in a non pre-formatted element such as a <p> or <span>, which adds a <br/> before the \n forcing HTML to render the break. <textarea> and <pre> tags are examples of pre-formatted elements, so linefeeds would be rendered as such.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    New Coder
    Join Date
    Dec 2012
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi,

    Below are the codes that I used to insert and retrieve from database.

    Form for user to enter:
    <textarea rows="5" cols="30" name="address"></textarea>

    Insert statement
    $address=$_POST["address"];
    mysql_query("INSERT INTO TABLE (address) VALUES ('$address')");

    Display
    $result=mysql_query("SELECT * FROM TABLE");
    $row=mysql_fetch_array($result);
    echo "Address: " . $row["address"];

    My database(phpmyadmin)
    Name: address
    Type: VARCHAR
    Length/Value: 800

  • #5
    New Coder
    Join Date
    Dec 2012
    Posts
    22
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi,

    Thanks for the advice.

    I tried using the nl2br in the output and it works fine.

    echo "Address: " . nl2br($row["address"]);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •