Insert Degree Symbol in database through PHP
database, mysql, php, symbols
Solution
- Don't use mysql_* functions, because they're deprecated. Learn about PDO instead, which is the way to do things nowadays.
- Do not save HTML-encoded characters. Always store them as UTF-8 (or your preferred charset, even if i suggest you UTF-8 anyway)
- If you store them as plain UTF-8 characters this issue will solve itself at once. Just remember that you need to call `htmlentities` or `htmlspecialchars` on the fetched values.
- Why are you storing your values as strings, rather than 4 separated fields? You'll be able to have much more flexibility (you can now make averages and all sorts of calculations with integers that you can't with strings) and you can leave the `°` issue to your page rendering script rather than wrestle with DB character encodings.
Sorry if I don't solve directly your issue, but I think that you'll be better off in the long run if you take the high road and tackle the root of the problem rather than the superficial issue.
Expecially n° 4. Really, consider that.
Problem
Hi StackOverflow friends, I am storing temperature in my database but I cannot add the degree symbol. My code is: ``` $que = "Insert into tblTempForecast (DateTimePosted, Now, Tomorrow) VALUES(now(),'$CloseLow1 ° - $CloseHi1 °','$CloseLow2 ° - $CloseHi2 °')"; $insertTemp = mysql_query($que); ``` My `$CloseLow1` is equal to 15 and `$CloseHi1` is 20. `$CloseLow2` is 18 and `$CloseHi2` is 22. However, with my code above, it only inserts the `$CloseLow1` and `CloseLow2`. It is supposed to insert the ff on the database: ``` ID (auto) DateTimePosted Now Tomorrow 1 2013-11-18 15:25:48 15°-20° 18°-22° ```