Re: re:store html codes in text field (mysql)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



mrfroasty wrote:
Sorry if this has been asked before but I cant seem to find anything
useful via google......
I have a text fields which stores my textarea input from a user, my
design is meant to allow user to submit html codes...but mysql seem to
replace all html tags with something else...

Example:
$title="some text";
$html_code=<h1>heading 1</h1>

INSERT INTO $db_table VALUES(null,'$title','$html_code')";

Result in my dB:
1]some text
2]&lt;h1&gt;heading &lt;h1&gt;

How can I solve this problem of mysql replacing the html tags.....?This
is probably something familiar to webdev, but I am kind of a noob in web
programming...

mysql is 100% not doing it. If you did that manually in mysql, you would get the right results.

mysql> create table test (html text);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into test(html) values ('<h1>heading 1</h1>');
Query OK, 1 row affected (0.00 sec)

mysql> select * from test;
+--------------------+
| html               |
+--------------------+
| <h1>heading 1</h1> |
+--------------------+
1 row in set (0.00 sec)

You have a htmlspecialchars or htmlentities call between $html_code being set and where you're doing the insert.

N:B
The only way I can think of is replacing them after pulling them out of
the dB, but I am not sure if this is the way to go...

See http://au.php.net/manual/en/function.html-entity-decode.php

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux