When I insert "<b>dog</b>" into database using php, it inserts empty string.
WHY???

How to fix it?

thnx in advance

Recommended Answers

All 8 Replies

ok... actually I knew that it is html entity, but the problem is how to save such converted string in database?

Say user makes new post and the post is "<b>dog</b>", so my script as usual is gonna save it in db, but it saves "".

i tried this query , is working for me:

insert into  `test` values('<b>dog</b>');

or else post your query.

when i do it directly with phpMyAdmin or console, the insertion is ok, however when via php it inserts nothing...

ya, then please post post your query,
it may be because of quotes in your query.

this code works for me:

<?php 
$str='&lt;b&gt;dog&lt;/b&gt;';
$str=htmlentities($str);
echo $q="insert into test values('$str')";
?>

I think I've found the problem but haven't found the solution yet: problem comes from the root - $_POST. If text sent from client is "&lt;b&gt;dog&lt;/b&gt;", then $_POST is empty, that's why php was inserting empty string. But if normal text is sent from client everything goes ok...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.