[RESOLVED] php mysql special characters
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 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.
Re: php mysql special characters
I think this is what you are looking for:
Code:
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:
Code:
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.
Re: php mysql special characters
Quote:
Originally Posted by
techgnome
I think this is what you are looking for:
Code:
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:
Code:
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:
Code:
Fatal error: Call to undefined function: html_entities() in
Dou you know why?
Re: php mysql special characters
because it would seem that it's htmlentities(). ... :)
http://us2.php.net/manual/en/function.htmlentities.php
-tg
Re: php mysql special characters
Thread moved from "CodeBank - PHP" forum to "PHP" forum
(thanks for letting us know tg :thumb: )
Re: php mysql special characters
Quote:
Originally Posted by
techgnome
I don't understand it, can you please explain.
Re: php mysql special characters
You used html_entities, but the function is actually called htmlentities (no _ )
Re: php mysql special characters
Quote:
Originally Posted by
si_the_geek
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:
Code:
<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
PHP Code:
//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.
Re: php mysql special characters
PHP Code:
$description = mysql_real_escape_string(htmlentities(nl2brnl($_POST['description'])));
Re: php mysql special characters
Excellent stuff guys thank you for your hard work and help.