Jump to content

Recommended Posts

Ok.. I'm building a CMS for my guild.

One thing that is constantly bugging me and breaking my scripts is if someone enters a character such as ó,í,é etc.

 

I've tried with php.ini has this -> default_charset = "utf-8"

I've tried with SQL database and tables set to utf8->utf8_general_ci

I've tried with <meta http-equiv="Content-type" value="text/html; charset=utf-8"> on every page load

I've tried with SET NAMES utf8; on every SQL connection.

 

The data needs to be stored in a mySQL db and stored in $_SESSIONs, the weird symbols keep breaking my scripts..

 

What do you guys do to solve this stupid problem?

Link to comment
https://forums.phpfreaks.com/topic/244960-damn-utf8/
Share on other sites

Ok let me give you a better example of what I mean..

 

Example..

<?php
  $str = 'Cóòkíémònztr';
  $_SESSION['name'] = $str;
  
  $q = $db->query(" INSERT INTO names (name) values ('".$_SESSION['name']."') ");
?>

 

Then, when I look in the database, it looks like this.. CóòkíémÃ

 

Current settings

.htaccess -> AddDefaultCharset utf-8

PHP.INI -> default_charset = "utf-8"

HTML -> <meta http-equiv="Content-type" value="text/html; charset=utf-8">

MySQL -> I've tried both utf8_bin and utf8_general_ci

Link to comment
https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258305
Share on other sites

What happens when you pull the data out and echo it? Same nonsense?

 

The following works fine for me

 

<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head>
<body>
<?php

$db = new mysqli('localhost','root','','db');

$str = 'Cóòkíémònztr';

$db->query(" INSERT INTO `test` (`name`) values ('".$str."') ");

$r = $db->query('SELECT `name` FROM `test`');

while( $d = $r->fetch_assoc() )
echo $d['name'].'<br>';

/* TABLE DUMP

CREATE TABLE IF NOT EXISTS `test` (
  `name` varchar(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

*/	

?>
</body>
</html>

 

It shows up bad in PHPMyAdmin oddly enough, considering it should use the UTF-8 charset.

Link to comment
https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258324
Share on other sites

I have my table dump included with my sample script.

 

CREATE TABLE IF NOT EXISTS `test` (
  `name` varchar(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

 

Perhaps the actual PHP file isn't encoded in UTF? It's gotta be on your side somewhere, as my example works flawlessly over here.

Link to comment
https://forums.phpfreaks.com/topic/244960-damn-utf8/#findComment-1258338
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.