MySQL insert statement and UTF-8 encoding!
Posted: Thu Jul 09, 2009 3:18 pm
Hi guys,
this my first post and i want to thank everybody who'll open my post and try to figure what the problem is. So here we go :
I have an Intranet using PHP/AJAX/MySQL, so some parts are pure PHP, others AJAX etc... i'm sure you got the thing already, i have many INSERT or UPDATE sql statements from users input. Some are from news users put on the Intranet, or on many other parts of the Intranet.
All the testing phase (from my side) has been made with FF under Linux, this is my Development box, i tested the Intranet with IE7 and 8 and it's working fine, but i have to do a check in all my INSERT or UPDATE statement, that if it's IE browser do:
It looks like FF is doing the utf8 encoding from input fields correctly but not IE, all the charsets are good and working good. If i look at the page properties under IE and FF, i have the same information concerning the charset and encoding.
I'm wondering, if any of you might have an idea on what the problem could be? For the moment, i've added the previous code to every important variables requiring correct encoding, but i want to find a way to fix the problem.
A little example for you :
Working with FF NOT working with IE
Working with IE NOT working with FF
Working with IE AND working with FF
I hope i've been clear enough,
thanks for your time!
this my first post and i want to thank everybody who'll open my post and try to figure what the problem is. So here we go :
I have an Intranet using PHP/AJAX/MySQL, so some parts are pure PHP, others AJAX etc... i'm sure you got the thing already, i have many INSERT or UPDATE sql statements from users input. Some are from news users put on the Intranet, or on many other parts of the Intranet.
All the testing phase (from my side) has been made with FF under Linux, this is my Development box, i tested the Intranet with IE7 and 8 and it's working fine, but i have to do a check in all my INSERT or UPDATE statement, that if it's IE browser do:
Code: Select all
$var = utf8_encode($var);I'm wondering, if any of you might have an idea on what the problem could be? For the moment, i've added the previous code to every important variables requiring correct encoding, but i want to find a way to fix the problem.
A little example for you :
Working with FF NOT working with IE
Code: Select all
header('Content-type: text/html; charset=utf-8');
$var = "Télévision";
$sql = "INSERT INTO tableX VALUES ('".$var."')";
Code: Select all
header('Content-type: text/html; charset=utf-8');
$var = "Télévision";
$var = utf8_encode($var);
$sql = "INSERT INTO tableX VALUES ('".$var."')";
Code: Select all
function isMSIE($agent)
{
if(eregi("MSIE",$agent))
return true;
else
return false;
}
Code: Select all
header('Content-type: text/html; charset=utf-8');
$var = "Télévision";
if(isMSIE($_SERVER['HTTP_USER_AGENT']) == true)
{
$var = utf8_encode($var);
}
$sql = "INSERT INTO tableX VALUES ('".$var."')";
thanks for your time!