Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-15-2010, 07:53 AM   PM User | #1
kodemonki
New to the CF scene

 
Join Date: May 2006
Location: Ann Arbor, MI
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
kodemonki is an unknown quantity at this point
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.
kodemonki is offline   Reply With Quote
Old 04-15-2010, 03:34 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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)); 
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 04-19-2010, 01:30 PM   PM User | #3
kodemonki
New to the CF scene

 
Join Date: May 2006
Location: Ann Arbor, MI
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
kodemonki is an unknown quantity at this point
Thanks! That was the answer
kodemonki is offline   Reply With Quote
Reply

Bookmarks

Tags
html insert, mysql insert, mysql_real_escape_string

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:34 AM.


Advertisement
Log in to turn off these ads.