Dear all

i have created a from to receive data from users. and data will store in sql table. all is going well. BUT NOW i have installed a module so users can type in Hindi fonts to fill details in form.

when users will type data in hindi font and submit, Data will store in sql table but not in hindi. it is like an machine language. And when i retrive data from table into page it will show the data in also machine language.


please help me to sort out this problem.


my main aim is to get user detail in hindi font and store in mysql table. and Retrive data in hindi font as required.

Thanks in advance

Below is mysql code.

CREATE TABLE `tbl_hindi` (
  `data` varchar(1000) character set utf8 collate utf8_bin default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `tbl_hindi` VALUES ('कंप्यूटर');

Below is PHP code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?
	mysql_connect('localhost','root','');
	mysql_select_db('test');
	mysql_query("SET NAMES utf8"); 
	
	$sql = "select * from tbl_hindi";
	$res = mysql_query($sql);
	$sar = mysql_fetch_assoc($res);
	echo $sar['data'];
?>
</body>
</html>

Hi

pls try to get the hindi values in unicode formate. it will be more help

thank

this is a good code. and work fine.

but when i insert data from a form in a php page which execute a query to insert data in to sql table it will not save data in hindi. it is changed the data into &^%$&$%32# like this.

please help me .

tell me how to get hindi data from a form in sql table

thanks

pls check, the data stored in the field structure, Collation should be utf8_unicode_ci

My fields of table where data will stored, collation is utf8_unicode_ci.

please write me complete code from html form to php page which execute query to store data in table.

Please it is very Important for me.

Please help

Gajendra

Member Avatar for diafol

OK, hindi characters will be stored as multibyte characters (2 or 3 stored characters for each visual character). If you're adding via php, e.g. in an utf-8 page:

नमस्ते

through this:

$sql = mysql_query("INSERT INTO foo SET `mane3` = 'नमस्ते'");

will be stored as this:

नमसà¥à¤¤à¥‡

(17 or so characters)

So for a 6 character field, you actually need to store it as 18 characters.

Also, if you're doing any length or strtolower etc sort of stuff, use the mb_* functions in php. MySQL strlen function is multibyte safe.

Thank dear for your help.

but still i not able to store data in sql table in Hindi fonts.

my html form is like this :--

<form action="submit.php" method="post">
Name:<input type="text" name="name" size="20" /><br />
Address:<input type="text" name="address" size="20" /><br />
Phone: <input type="text" name="phone" size="20" /><br />
City:<input type="text" name="city" size="20" /><br />
State<input type="text" name="state" size="20" /><br />
<input type="submit" value="Register" />
</form>

And my php page which store data in sql table is :-

<?php
$name=$_POST;

echo $name;

$con=mysql_connect("localhost","root","");

mysql_select_db("register",$con);


$query=mysql_query("INSERT INTO users VALUES (null,'$name')");

mysql_close($con);

?>

Data had store in sql table but not in hindi format it looks like :--


गलनफà¥à¤«

and when i retrieve data from sql table in php page is also looks like above.

plz tell what i have to do ?

thanks in advance

Below is mysql code.

CREATE TABLE `tbl_hindi` (
  `data` varchar(1000) character set utf8 collate utf8_bin default NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `tbl_hindi` VALUES ('कंप्यूटर');

Below is PHP code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?
	mysql_connect('localhost','root','');
	mysql_select_db('test');
	mysql_query("SET NAMES utf8"); 
	
	$sql = "select * from tbl_hindi";
	$res = mysql_query($sql);
	$sar = mysql_fetch_assoc($res);
	echo $sar['data'];
?>
</body>
</html>

I didnt get why this is not working for you.
See attached image, it works for me.

Member Avatar for diafol

Ensure that your page is encoded with utf-8.

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />

In the head area.

@vibhadevit - did you add data via the phpMySQL query box OR direct input OR php sql statement?

i dont know whats going wrong.

can you please send me your html form and php page code which store data in sql table. if i sotre data in sql table by cut and paste it will be in hindi. but when i store data by from . it will be converted in to symbols.

please send me your html form code and php page code

I have tried with following php code to insert hindi data.
And also using phpmyadmin tab.

<?
	mysql_connect('localhost','root','');
	mysql_select_db('test');
	
	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');
	
	$sql = "insert into tbl_hindi values ('कंप्यूटर कंप्यूटर ')";
	mysql_query($sql);
	
	$sql = "select * from tbl_hindi";
	$res = mysql_query($sql);
	while($sar = mysql_fetch_assoc($res))
	{		
		print_r($sar);
	}
?>

i had done all the things which is you told me. but i cant achieve my aim.

please send me complete code of html form and php page of storing data in sql table.


thanks

thanks dear,

it is also going better with me if i put data directly in sql query. but when i pur data from a php variable which store data from html from and try to store it in sql table it will changed.

please try to store data by a html form.

first of all fill the html form and get data in a php page.
and then store data in sql table by executing a query there.

Member Avatar for diafol

The fact that it looks like gibberish in the DB is no problem. If you have the proper DB and html page encoding in place, it should echo back out correctly.

With form ...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?
	/* CREATE TABLE `tbl_hindi` (
	  `data` varchar(1000) character set utf8 collate utf8_bin default NULL
	) ENGINE=InnoDB DEFAULT CHARSET=latin1;
	
	INSERT INTO `tbl_hindi` VALUES ('कंप्यूटर'); */
	
	mysql_connect('localhost','root','');
	mysql_select_db('test');	
	
	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');
	
	if(isset($_POST['save']))
	{
		$sql = "insert into tbl_hindi values ('".$_POST['data']."')";
		mysql_query($sql);
	}
	
	$sql = "select * from tbl_hindi";
	$res = mysql_query($sql);		
		
?>
<form  method="post">
<table width="900%" border="0">
  <tr>
    <td>Add New : <input type="text" name="data" size="20" />
<input type="submit" name="save" value="Save" /></td>
  </tr>
  <tr>
    <td>-----------------------------</td>
  </tr>
  <tr>
    <td><strong>Hindi Data</strong></td>
  </tr>
  <? while($sar = mysql_fetch_assoc($res)) { ?>
  <tr>
    <td><?=$sar['data'];?></td>
  </tr>
  <? } ?>
</table>
</form>
</body>
</html>
commented: nice one - like it +13

thanks dear but it is not working . it is not storing data in table.

see this sanp after click on save button noting will happen. just only input box will be empty. nothing will stored in sql table.

please tell me other way to store hindi data in sql table.


thanks

Hi

vibha


i dont know how to attach a file in message here. so i am replying you by this way.

plz check i am sending you another sanp of you code.


Gajendra

As i asked you before your php open tag seems closed. Try below code.

<?php error_reporting(E_ALL);?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
	/* CREATE TABLE `tbl_hindi` (
	  `data` varchar(1000) character set utf8 collate utf8_bin default NULL
	) ENGINE=InnoDB DEFAULT CHARSET=latin1;
	
	INSERT INTO `tbl_hindi` VALUES ('कंप्यूटर'); */
	
	mysql_connect('localhost','root','');
	mysql_select_db('test');	
	
	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');
	
	if(isset($_POST['save']))
	{
		$sql = "insert into tbl_hindi values ('".$_POST['data']."')";
		mysql_query($sql);
		echo '<br />Data inserted successfully.<br />';
	}
	
	$sql = "select * from tbl_hindi";
	$res = mysql_query($sql);		
		
?>
<form  method="post">
<table width="900%" border="0">
  <tr>
    <td>Add New : <input type="text" name="data" size="20" />
<input type="submit" name="save" value="Save" /></td>
  </tr>
  <tr>
    <td>-----------------------------</td>
  </tr>
  <tr>
    <td><strong>Hindi Data</strong></td>
  </tr>
  <?php while($sar = mysql_fetch_assoc($res)) { ?>
  <tr>
    <td><?php echo $sar['data'];?></td>
  </tr>
  <?php } ?>
</table>
</form>
</body>
</html>

What happened??
Is this fixed???

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.