Reputation: 1
I've been given a project to work on wherein i need to create a Database that can store and retrieve non english data. I've looked up and made all my connections to UTF. however,everytime it inserts into the DB,and the no. of rows get incremented but i only get blank fields in my DB.
<html>
<body>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_query('SET character_set_results=utf8');
mysql_query('SET names=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_results=utf8');
mysql_query('SET collation_connection=utf8_general_ci');
mysql_select_db('Hindi',$con);
$nith = "CREATE TABLE IF NOT EXISTS `HINDI` (
`data` varchar(1000) character set utf8 collate utf8_bin default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1";
if (!mysql_query($nith,$con))
{
die('Error: ' . mysql_error());
}
$Name = $_POST['Name'];
$nithi = "INSERT INTO `HINDI`
"(Name) ".
VALUES ('$Name')";
if (!mysql_query($nithi,$con))
{
die('Error: ' . mysql_error());
}
/*
$result = mysql_query("SET NAMES utf8");//the main trick
$cmd = "select * from HINDI";
$result = mysql_query($cmd);
while($myrow = mysql_fetch_row($result))
{
echo ($myrow[0]);
}
*/
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Employee Name</td>
<td><input name="emp_name" type="text" id="emp_name"></td>
</tr>
<input name="add" type="submit" id="add" value="Add Employee">
</td>
</table>
</form>
</body>
</html>
Upvotes: 0
Views: 1099
Reputation: 1
Check what rdanusha and quncage have asked.
Also check whether your php file is utf-8 encoded.
Also add accept-charset="utf-8" in your form attributes.
For example http://www.w3schools.com/tags/att_form_accept_charset.asp
Upvotes: 0
Reputation: 1579
One thing that could be making it troublesome for you is the charset encoding of your PHP documents. If they are encoded in ASCII (some text editors create documents like this as standard) it will not work properly.
You could download Notepad++ for free and open your document, go to encoding and if your document isn't UTF-8, select convert to UTF-8 without BOM. Do this with all of your PHP documents.
Upvotes: 0
Reputation: 923
Did you change Collation to utf8_general_ci in your database table ?
Upvotes: 1