PDA

Click to See Complete Forum and Search --> : [RESOLVED] php mysql special characters


BHCluster
Jun 6th, 2009, 12:47 PM
Hi everyone, let me start by explaining the problem which I am having. I have a simple php, mysql application that ads, edits and deletes records, however my problem arises when I redisplay some edited text in a way:

Lets say I use € symbol in html it is € so in my form entry I would write "€ 50" and save it so when the web page is viewed it will show € 50, so when I try to edit the number ot lets say 30 back in may edit page it will say €50 and when I re-save it it stores back into the db this "€ 50", so I was wondering if that has to do with php mysql special characters and how do I bypass it, any help is appreciated.

This is my code:

<?php
if ($nid>0) {
$query=mysql_query("SELECT * FROM `nekretnine` WHERE `nid`='".$nid."' LIMIT 1");
while ($fetch=mysql_fetch_assoc($query)) {
<form action="edit.php?id=<?php echo $nid; ?>" method="post">
print '<textarea id="textarea" type="text" name = "description" />'.$fetch['description'].'';
print ' </textarea>';
print '<input type="submit" value="Dodaj">';
print "</form>";
}
} else {
print '<tr><td colspan="4">Not Saved try again</td></tr>';
}
?>


I've red somwhere that I should use "html_entities(mysql_real_escape_string($variable));" but I don't know how to insert it in my code.

Thank you.

techgnome
Jun 6th, 2009, 01:36 PM
I think this is what you are looking for:

print '<textarea id="textarea" type="text" name = "description" />'.html_entities($fetch['description']).'';

Not sure what the mysql_real_escape_string function is or does... but if it turns out you need it then it looks like this:


print '<textarea id="textarea" type="text" name = "description" />'.html_entities(mysql_real_escape_string($fetch['description'])).'';

Hope that helps....

-tg
ps - this shouldn't be in the codebank, which is for sharing usefull stull... I'll let a mod know to move it.

BHCluster
Jun 6th, 2009, 02:18 PM
I think this is what you are looking for:

print '<textarea id="textarea" type="text" name = "description" />'.html_entities($fetch['description']).'';

Not sure what the mysql_real_escape_string function is or does... but if it turns out you need it then it looks like this:


print '<textarea id="textarea" type="text" name = "description" />'.html_entities(mysql_real_escape_string($fetch['description'])).'';

Hope that helps....

-tg
ps - this shouldn't be in the codebank, which is for sharing usefull stull... I'll let a mod know to move it.

Thanks for answering so quickli but when I do what you have suggested I get this error:
Fatal error: Call to undefined function: html_entities() in
Dou you know why?

techgnome
Jun 6th, 2009, 07:56 PM
because it would seem that it's htmlentities(). ... :)

http://us2.php.net/manual/en/function.htmlentities.php

-tg

si_the_geek
Jun 7th, 2009, 04:40 AM
Thread moved from "CodeBank - PHP" forum to "PHP" forum

(thanks for letting us know tg :thumb: )

BHCluster
Jun 7th, 2009, 09:43 AM
because it would seem that it's htmlentities(). ... :)

http://us2.php.net/manual/en/function.htmlentities.php

-tg

I don't understand it, can you please explain.

si_the_geek
Jun 7th, 2009, 10:01 AM
You used html_entities, but the function is actually called htmlentities (no _ )

BHCluster
Jun 7th, 2009, 12:31 PM
You used html_entities, but the function is actually called htmlentities (no _ )

Thanks for that!

One more thing If I have a form which I use to input this information and it goes something like this:


<form enctype="multipart/form-data" action="add.php" method="POST">
<textarea style="width:250px;height:80px;overflow:auto;" type="text" name = "description" />
</form>


add.php

//This gets all the other information from the form
$description=$_POST['description'];
//Writes the information to the database
mysql_query("INSERT INTO `det` VALUES ('','$description')") ;



How would I incorporate htmlentities() in to the code so it would store all of the special characters, and also how would I incorporate nl2brnl() into this code as well. I really appreciate your help.

kows
Jun 7th, 2009, 08:32 PM
$description = mysql_real_escape_string(htmlentities(nl2brnl($_POST['description'])));

BHCluster
Jun 9th, 2009, 07:32 AM
Excellent stuff guys thank you for your hard work and help.