Hi,
I stored hindi data in my my sql table through Php form.
While fetching,it is not coming in hindi but some unusual symbols like गिरधर गोपाल रायतानॠis coming.

using below code also

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');

Need help..

Recommended Answers

All 11 Replies

In phpmyadmin table, is it visible as hindi text or symbols?

Which data type r u using for hindi data?

In phpmyadmin table, is it visible as hindi text or symbols?

In table it is visible in hindi correctly but during fetching i am getting error(symbols)
I change the collation to utf8_unicode_ci

mysql_query('SET character_set_results=utf8');

Do you have this code in top of your page?

mysql_query('SET character_set_results=utf8');

Do you have this code in top of your page?

this code is after some HTML code.

<?php session_start();
if (!isset($_SESSION['username']))
{
header('Location: login.php');
}
?>

<html>
<head>
<link rel="stylesheet" href="font.css"  type="text/css">
<title>Jai Sakhi Baba:City wise result</title>
<style type="text/css">

table, th
{
border:1px solid #666666;
font-family:Verdana;
font-size:small;
vertical-align:top;
}
th
{
background-color:#666666;
color:white;
}
td
{
 font-size:small;	
	
}
}
</style>
</head>
<table width="800px" align="center">
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <tr><td><a href="index1.php"><img src="images/home.jpg"></a></td>
  <td align="right"><b>Welcome :&nbsp;</b> <?php echo $_SESSION['username']; ?>&nbsp;&nbsp;<a href="logout.php" >Logout</a></td>
  </tr>
  <tr><td align="center"> <strong>Select:</strong>&nbsp;&nbsp;
  <input type="checkbox" name="a[]" value="name">Name
		<input type="checkbox" name="a[]" value="father">Father Name&nbsp;
 <font color="red">City:</font> <select name="users">
		<?php
		include('db_hindi.php');
		mysql_query('SET character_set_results=utf8');
		$sql="SELECT DISTINCT city FROM `tbl_hindi`";
		$result =mysql_query($sql);
		
		while ($data=mysql_fetch_array($result))
		{
		echo "<option value='$data[city]'>$data[city]</option>\n";
		}
		?>
		</select>
		&nbsp;Gender<select name="gender">
		<?php
		$gen="SELECT DISTINCT gender FROM `tbl_hindi` ORDER BY GENDER DESC";
		$result_gen=mysql_query($gen);
		while($row=mysql_fetch_array($result_gen))
		{
		echo "<option value='$row[gender]'>$row[gender]</option>\n";
		}
		?>
		
		</select>
		<input type="checkbox" name="a[]" value="address">Address
	
		
		</tr>
		<tr>
		<td align="center">
		<input type="checkbox" name="a[]" value="mobile">Contact
		<input type="checkbox" name="a[]" value="dob">DOB
		<input type="checkbox" name="a[]" value="namdan_date">Namdan date
		</td>
		
		</tr>
		<tr><td colspan="2" align="center"><input type="submit" name="submit" value="submit"></td></tr>
  </form>
  </table>
  </body>
 </html>
<?php
if(isset($_POST['submit']))
{
	mysql_query("SET NAMES utf8");
$city=$_POST['users'];
$gender=$_POST['gender'];
$sql = "SELECT";
	$check = (array) $_POST['a'];
	for($i = 0; $i < count($check); $i++) 
	{
		$sql .= ($i == (count($check)-1)) ? " `$check[$i]`" : " `$check[$i]`,";
	}
	 $sql .= " from tbl_hindi where city='$city' AND gender='$gender' order by gender desc ,namdan_date desc";
	$result = mysql_query($sql);
	$count=count($_POST['a']);
	//echo '<br>'.$count.'<br>';
	//$th="<table border=\"1px black solid\";><tr>";
	//for($j=0; $j<$count; $j++)
		//$th.="<th>$check[$j]</th>";
	//echo $check[$j];
//$result=("SELECT * from tbl_hindi where city='$city'");
//$result = mysql_query("SELECT * from tbl_hindi where city='$city'");
echo "<table border='1' align='center' class='font'>
<tr>
<td align='center' class='font' colspan='9' bgcolor='#666666'><b><font color='white'>Members Details</font></b></th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr class='font'>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['address'] . "</td>";
  echo "<td>" . $row['father'] . "</td>";
  echo "<td>" . $row['mobile'] . "</td>";
  echo "<td>" . $row['dob'] . "</td>";
  echo "<td>" . $row['namdan_date'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
}
?>
<div align="center"><a href="javascript:window.print();">Click here to Print</a></div>

Put that line in top of your page and try...

Put that line in top of your page and try...

Now getting different symbols दिनेश कà¥à¤®à¤¾à¤° चैनानी
but not getting hindi fonts

I have used the following code for displaying Tamil fonts. Its working fine for me. Compare this for hindi

<?php
	include "admin/includes/connectDB.php";
	mysql_query('SET character_set_results=utf8');
	extract($_POST);
	//print_r($_POST);
	if($txtNo!="")
	{
		........
                ........
		
		$qry_ans_tamil="select answer from tbl_tamil where ans_no=$num";
		$rs_ans_tamil=mysql_query($qry_ans_tamil);
		$ans_tamil=@mysql_result($rs_ans_tamil,0,"answer");
		
		........
		
		
	}
?>
<!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>
........
........

</head>

<body>
.......
.......
                            
                            <div style="height:auto; width:410px; margin-top:10px; padding:10px; margin-right:5px; background-color:#800000; ">
                       		  <div style="font-family:Verdana, Geneva, sans-serif; font-size:13px; font-weight:bold; color:#fbcf97">
                              		<?php
										if(isset($ans_tamil))
											echo $ans_tamil;
										
									?>
                              </div>
                            </div>
                            
                            ...........
                            ...........
</body>
</html>

it is bad practice to store Hindi chars in database.. better way is to convert it into hexadecimal and store in db. and at the time of display reconvert it into unicode from hexadecimal.. i did the same thing for arabic content..!!

how to fetching hindi language in database from mysql php in detail sep by by step..?
id-nitishitmit@gmail.com

Member Avatar for diafol

DB character set = utf8
collation = utf8_unicode_ci

Should see you be able to use mysql as normal

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.