how to save another language to mysql db using php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shikhar
Forum Newbie
Posts: 3
Joined: Thu Jul 21, 2011 9:52 am

how to save another language to mysql db using php

Post by shikhar »

Hi

I am trying to add the data in Hindi from a html "text field" to mysql database using the php script.

It is not inserting the hindi text, it is inserting the English fonts.

Could anyone please help me to over come.

This is my html code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>My Hindi Text Insertion</title>
</head>

<body>
<form action="submithindi.php">
F Name : <input type="text" name="txtfname" id="txtfname" style="font-family:'Kruti Dev 010'; font:'Kruti Dev 010'" />

L Name :<input type="text" name="txtlname" id="txtlname" style="font-family:'Kruti Dev 010'; font:'Kruti Dev 010'" />

<input type="submit" />
</form>
</body>
</html>

This is my PHP code snippet:
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("student", $con);

$fname = $_REQUEST["txtfname"];
$lname = $_REQUEST["txtlname"];

$query = mysql_query("insert into dlist(fname, lname) values('$fname', '$lname')") or die(mysql_error());
?>

Thi is smy MySql table structure: Please note that i followed the complete steps you have mentioned to create database & table.

fname char(20) utf8_general_ci Yes NULL

lname char(20) utf8_general_ci Yes NULL



Thanks & regards,


bhatnagar shikhar
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: how to save another language to mysql db using php

Post by internet-solution »

You need to convert the user input to utf8 - http://php.net/manual/en/function.utf8-encode.php
Post Reply