unistake Posted August 13, 2009 Share Posted August 13, 2009 Hi all, In my mysql database I have a small note about a product e.g. "this retails at £29.99". The problem is that when I come to echo this $note in php it does not display the £ character but a black diamond shape with a question mark in it! The mysql field is a VARCHAR length 100. How can this be changed so it displays the £ sign? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/ Share on other sites More sharing options...
Adam Posted August 13, 2009 Share Posted August 13, 2009 Try using htmlspecialchars as you output the data, if no success you may need to convert using htmlspecialchars() as you *input* the data. Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-897238 Share on other sites More sharing options...
unistake Posted August 13, 2009 Author Share Posted August 13, 2009 MrAdam, thanks for the reply. where would i put that, whilst creating a table in mysql? Could you give me an example? thanks Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-897246 Share on other sites More sharing options...
Adam Posted August 13, 2009 Share Posted August 13, 2009 Read the link I sent you, should have an idea then! I can't tell you where to put it now though cause I have no idea what your code is like... Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-897251 Share on other sites More sharing options...
unistake Posted August 13, 2009 Author Share Posted August 13, 2009 ah! missed the link - thanks Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-897255 Share on other sites More sharing options...
unistake Posted August 20, 2009 Author Share Posted August 20, 2009 I am still having trouble to get this to work. The field in mysql is accessed with php and the variable being $details. It is a VARCHAR (100 length) and can include text along with a price with the sterling symbol. When i come to echo the $details it comes up with a � symbol. I have tried $details = htmlspecialchars($details); and then echoing $details in php, but i am not sure that is how to use the htmlspecialchars in this particular case??? Can anyone show me how to use it ? Thanks Tim Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-902199 Share on other sites More sharing options...
Adam Posted August 20, 2009 Share Posted August 20, 2009 Post the relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-902371 Share on other sites More sharing options...
unistake Posted August 20, 2009 Author Share Posted August 20, 2009 <head> <script> function DoNav(theUrl) { document.location.href = theUrl; window.open(theUrl, 'newwindow'); } </script> </head> <body> <? $cxn = mysqli_connect($host, $user, $password, $database) or die ("cant connect to the database"); $query = "SELECT * FROM database"; $result = mysqli_query($cxn,$query) or die ("Can't execute query!"); echo "<table width='900' cellspacing='0' cellpadding='10'>"; while ($row = mysqli_fetch_assoc($result)) { extract($row); $details = htmlspecialchars($details); echo "<tr onclick=\"DoNav('$link');\"> <td><img src='images/bmks/$name.jpg' width='100' height='30' /></td> <td class='display'>$name</td> <td class='display'>£$price</td> <td class='display'>$minodds</td> <td class='display'>$sr</td> <td class='display'>$pf</td> [size=4] <td class='display'>$details</td>[/size] </tr>"; } echo "</table>"; ?> </body> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-902428 Share on other sites More sharing options...
fenway Posted August 21, 2009 Share Posted August 21, 2009 $query = "SELECT * FROM database"; Can't possibly not work. Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-903229 Share on other sites More sharing options...
unistake Posted August 21, 2009 Author Share Posted August 21, 2009 $query = "SELECT * FROM database"; Can't possibly not work. It seems to work fine! Howcome though?! Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-903600 Share on other sites More sharing options...
fenway Posted August 22, 2009 Share Posted August 22, 2009 Yes, I agree that it's fine... so where's the mysql issue? Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-903993 Share on other sites More sharing options...
unistake Posted August 22, 2009 Author Share Posted August 22, 2009 the issue with using htmlspecialchars, and mysql database data. Please dont try to be smart! If you dont know the answer then leave it! Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-904093 Share on other sites More sharing options...
kickstart Posted August 22, 2009 Share Posted August 22, 2009 Hi To use htmlspecialchars you could just do:- <td class='display'>".htmlspecialchars($details)."</td> However I doubt that this is the problem (do a view source on the generated page to see what has been output, rather than what the browser has translated it to). I would suspect it is something to do with character sets. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-904147 Share on other sites More sharing options...
unistake Posted August 22, 2009 Author Share Posted August 22, 2009 hi Keith, thanks for the help. I think you were right, that code you gave me did not correct it. I also checked the page source and it is showing the � symbol instead of the £ sign. Is that what you were talking about? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-904166 Share on other sites More sharing options...
kickstart Posted August 22, 2009 Share Posted August 22, 2009 Hi It was. It is odd that the source contains a |. Can you see the table data (ie, in phpmyadmin or equivalent). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-904174 Share on other sites More sharing options...
corbin Posted August 23, 2009 Share Posted August 23, 2009 To store/display £, the following must be true: The connection the the database must be UTF8 (or some charset that supports £). The browser must be told that the data being sent to it is UTF8 (or what ever charset). Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-904261 Share on other sites More sharing options...
fenway Posted August 25, 2009 Share Posted August 25, 2009 the issue with using htmlspecialchars, and mysql database data. Please dont try to be smart! If you dont know the answer then leave it! Those are separate issues -- kickstart is trying to figure out which side is the problem. I was simply trying to determine if the data is coming back properly, irrespective of htmlspecialchars(), with has nothing to do with mysql. Quote Link to comment https://forums.phpfreaks.com/topic/170083-mysql-statement-error/#findComment-905929 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.