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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Location
    Ann Arbor, MI
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Inserting HTML into MySQL

    I know this is a very common question, and have found consistent answers online, but I can't seem to get this to work for me. I am trying to input:

    Code:
    <div id="394" class="ui-draggable item_outfit" style="left: 234px; top: 177px; width: 150px; height: 200px; position: absolute; display: block;"></div><div id="10" class="ui-draggable item_outfit" style="left:32px; top:392px; height:150px; width:300px; position:abolute; display:block;"></div>
    into MySQL.

    Here's what I've done:

    Code:
    $look = '<div id="394" class="ui-draggable item_outfit" style="left: 234px; top: 177px; width: 150px; height: 200px; position: absolute; display: block;"></div><div id="10" class="ui-draggable item_outfit" style="left:32px; top:392px; height:150px; width:300px; position:abolute; display:block;"></div>';
    
    $look2 = htmlentities($look);        
    $look3 = html_entity_decode(htmlentities($look));
    $look4 = mysql_real_escape_string($look);
              
    $user_id = 34;
                                      
    $query = "insert into user_outfits (user_id, div) values ($user_id, '" . mysql_real_escape_string($look) . "')";
    echo $query;
    $create_outfit = mysql_query($query);
    I have tried the query with look (using mysql_real_escape_string()), look2, look3, and look4, to no avail. When I echo each look variable, only look2 is displayed correctly. Echoing look, look3 and look4 give me null values, and when I echo the query I get

    Code:
    insert into user_outfits (user_id, div) values (34, '
    ')
    Why won't this insert into the database?

    Thanks in advance.

  • #2
    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
    Does echoing really not show anything, or are you just viewing it in the browser? View you're source to confirm that there is no HTML available within the query itself; viewing the output in a browser is pretty much pointless since it will convert this to parsed html. If you intend to store parsable HTML within the database, all you should need is the mysql_real_escape_string to prevent it from clobering your query. Otherwise, you'll need to use htmlentities or htmlspecialchars in order to convert it to the text display so you can then print a viewable text of it online. Look into using the strip_tags function to control what you allow; definitely don't want say <php> or <script> to be added to that.

    If its not being inserted, kill your query to find out why:
    PHP Code:
    $create_outfit mysql_query($query) or die(sprintf("Error: %s\nQuery: %s\n"mysql_error(), $query)); 
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    May 2006
    Location
    Ann Arbor, MI
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks! That was the answer


  •  

    Tags for this Thread

    Posting Permissions

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