jasonc Posted June 10, 2011 Share Posted June 10, 2011 I have been having problems getting the £ sign to be inserted as a £, what is the correct method to insert it in to mysql ? Quote Link to comment https://forums.phpfreaks.com/topic/238955-how-to-correctly-insert-a-%C2%A3-into-mysql-table-so-it-shows-as-a-%C2%A3-and-not-a%C2%A3/ Share on other sites More sharing options...
pastcow Posted June 10, 2011 Share Posted June 10, 2011 I think you need to make sure the DB table supports the correct charset and that when you display it from the DB its supporting the page you display it on sets the correct charset. Quote Link to comment https://forums.phpfreaks.com/topic/238955-how-to-correctly-insert-a-%C2%A3-into-mysql-table-so-it-shows-as-a-%C2%A3-and-not-a%C2%A3/#findComment-1227906 Share on other sites More sharing options...
jasonc Posted June 10, 2011 Author Share Posted June 10, 2011 i look at the database and it shows also as the £12 the Collation is set as latin1_swedish_ci is that the right Collation for this character ? Quote Link to comment https://forums.phpfreaks.com/topic/238955-how-to-correctly-insert-a-%C2%A3-into-mysql-table-so-it-shows-as-a-%C2%A3-and-not-a%C2%A3/#findComment-1227915 Share on other sites More sharing options...
jasonc Posted June 10, 2011 Author Share Posted June 10, 2011 this is an extract of my mysql table... CREATE TABLE IF NOT EXISTS `table` ( `id` int(25) NOT NULL auto_increment, `additionalInfo` text NOT NULL, `cost` varchar(100) NOT NULL, `admin_reply` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; the fields that are not showing the £ sign are 'cost' and 'admin_reply' Quote Link to comment https://forums.phpfreaks.com/topic/238955-how-to-correctly-insert-a-%C2%A3-into-mysql-table-so-it-shows-as-a-%C2%A3-and-not-a%C2%A3/#findComment-1227918 Share on other sites More sharing options...
The Little Guy Posted June 10, 2011 Share Posted June 10, 2011 When you do your query: mysql_set_charset('utf-8'); mysql_query("insert into table (...) values (...)"); Quote Link to comment https://forums.phpfreaks.com/topic/238955-how-to-correctly-insert-a-%C2%A3-into-mysql-table-so-it-shows-as-a-%C2%A3-and-not-a%C2%A3/#findComment-1227926 Share on other sites More sharing options...
jasonc Posted June 10, 2011 Author Share Posted June 10, 2011 i tried that and also changed the databases collation to utf8_general_ci, and still the same thing ? Quote Link to comment https://forums.phpfreaks.com/topic/238955-how-to-correctly-insert-a-%C2%A3-into-mysql-table-so-it-shows-as-a-%C2%A3-and-not-a%C2%A3/#findComment-1227935 Share on other sites More sharing options...
The Little Guy Posted June 10, 2011 Share Posted June 10, 2011 what do you do when you pull the data out? Quote Link to comment https://forums.phpfreaks.com/topic/238955-how-to-correctly-insert-a-%C2%A3-into-mysql-table-so-it-shows-as-a-%C2%A3-and-not-a%C2%A3/#findComment-1227937 Share on other sites More sharing options...
jasonc Posted June 10, 2011 Author Share Posted June 10, 2011 ok i now got it to store in the mysql as a £ not the A£ using the following method.. placing mysql_query("SET NAMES 'utf8'"); just below the call to mysql_select_db(); but still in the email text it shows as A£ the data is grabbed from mysql and placed in a string as is, then placed in a $_SESSION and then once the form is sumitted the new page formats the email text using strings and this is added to the email html, again none of these strings that have the £ are altered in anyway. Quote Link to comment https://forums.phpfreaks.com/topic/238955-how-to-correctly-insert-a-%C2%A3-into-mysql-table-so-it-shows-as-a-%C2%A3-and-not-a%C2%A3/#findComment-1227954 Share on other sites More sharing options...
The Little Guy Posted June 10, 2011 Share Posted June 10, 2011 Same thing: mysql_set_charset('utf-8') == mysql_query("SET NAMES 'utf8'") php recommends mysql_set_charset over mysql_query("SET NAMES 'utf8'") when you pull the data out of the database, I don't think you want to use mysql_set_charset over mysql_query("SET NAMES 'utf8'"). I believe I had that problem once, by removing that, it came out normal (it may have been vise versa but I don't think so). Quote Link to comment https://forums.phpfreaks.com/topic/238955-how-to-correctly-insert-a-%C2%A3-into-mysql-table-so-it-shows-as-a-%C2%A3-and-not-a%C2%A3/#findComment-1227957 Share on other sites More sharing options...
jasonc Posted June 10, 2011 Author Share Posted June 10, 2011 so when i insert i use mysql_set_charset('utf-8'); and when i grab i do not use the above ? that is going to be really hard to do as the connection.inc file is in every file that uses a database connection ! Quote Link to comment https://forums.phpfreaks.com/topic/238955-how-to-correctly-insert-a-%C2%A3-into-mysql-table-so-it-shows-as-a-%C2%A3-and-not-a%C2%A3/#findComment-1227962 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.