SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Storing HTML code in an Mysql database

    Does anyone know how to store text containing html code into a blob field in a mysql database?

  2. #2
    SitePoint Addict
    Join Date
    Apr 2001
    Location
    None
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't matter what you store text or html - same way.

  3. #3
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do you want to store it in a BLOB? Use a text field

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  4. #4
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In my sql I say

    $sql= " INSERT INTO adds
    SET ADDTEXT = '$buffer',
    ADDDATE = CURDATE() ";
    if (!@mysql_query($sql)) {
    echo("<p> Record not added" .mysql_error() .
    "</p>");
    exit();
    }

    Because $buffer contains htlm characters I am
    getting a parse error.

  5. #5
    SitePoint Guru
    Join Date
    Jan 2001
    Location
    Alkmaar, Netherlands
    Posts
    710
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try adding some slashes
    PHP Code:
    $slashedBuffer AddSlashes($buffer);
    $sql" INSERT INTO adds 
    SET ADDTEXT = '
    $slashedBuffer', 
    ADDDATE = CURDATE() "

    if (!@
    mysql_query($sql)) { 
    echo(
    "<p> Record not added" .mysql_error() . 
    "</p>"); 
    exit(); 


  6. #6
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Storing HTML code in an Mysql database

    Thank you for response.

    Is Addslashes a PHP function or is it a subroutine? Where can I get information concerning addslashes?

  7. #7
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here http://www.php.net/manual/en/function.addslashes.php

    Did you read my post above?

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  8. #8
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by seanf
    Why do you want to store it in a BLOB? Use a text field
    as far as i know, it shouldn't really matter. yes, i would suggest using TEXT too, for consistency. but BLOB shouldn't hurt anything. actually, i'm not sure if storing binary data in a TEXT column would hurt anything either.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  9. #9
    Are you ready for BSD? Marshall's Avatar
    Join Date
    Dec 2001
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You many want to use a method other than addslashes() for escaping SQL strings. See http://www.sitepointforums.com/showt...threadid=43061.

    - Marshall

  10. #10
    SitePoint Member
    Join Date
    Dec 2001
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The addslashes worked just fine for my application. I did not have to use stripslashes to get the data back in a form that I needed but I am not through yet. I will need to put the reteived data into an html page.

    Thanks for the help.


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
  •