SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Story Input

  1. #1
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Story Input

    How do you make a textarea in a form support html inserted content,
    so that I can input something like.

    <a href="url.html">Url link</a> and then it is displayed as a link when it is called from the database,

    Hope i am being clear enough

    -Mark

  2. #2
    SitePoint Evangelist
    Join Date
    Feb 2004
    Location
    Sofia, Bulgaria
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    // if your textarea is called 'htmltext'.. put the text into $str variable..
    $str $_POST['htmltext'];
    // escape the string to make it safe for MySQL..
    $str mysql_escape_string($str);
    // put the data in the database...

    // get the data from the database into $str variable..
    $str stripslashes($str);
    // and display it..
    echo $str

  3. #3
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so, would it be done like this, say for example we are using main_content


    $main_content= $_POST['main_content'];
    // escape the string to make it safe for MySQL..
    $main_content = mysql_escape_string($main_content);
    // put the data in the database...

    // get the data from the database into $str variable..
    $main_content = stripslashes($main_content);
    // and display it..
    echo $main_content;

    Is that how it works!?

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2004
    Location
    Sofia, Bulgaria
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, that should work.. you must add some additional code in place of comments to get it working indeed but that's the basic idea..

  5. #5
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dacool, I realise I have to add some extra code, the only bit I was unsure about was if I could use the $main_content string all the way through. Or weather I had to get it using ,

    $main_content= $_POST['main_content'];

    and then the string name had to change for this next bit

    $main_content_again = mysql_escape_string($main_content);

    If that makes sense! he he!

    Thanks

    Mark.

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2004
    Location
    Sofia, Bulgaria
    Posts
    421
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one correction to my code.. you don't have to use stripslashes() when you get the data from DB, because the MySQL will return the data without the slashes.. my mistake, sorry.. so the code will be:
    PHP Code:
    // if your textarea is called 'htmltext'.. put the text into $str variable.. 
    $str $_POST['htmltext']; 
    // escape the string to make it safe for MySQL.. 
    $str mysql_escape_string($str); 
    // put the data in the database... 

    // get the data from the database into $str variable.. 
    // and display it.. 
    echo $str

  7. #7
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hiya Dacool,

    Thanks for your speedy reply again.

    and for the update of the code, much appreciated!

    Mark.


Bookmarks

Posting Permissions

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