How to store the data in unicode in hindi language.
welcome back to shortlearner.com, in the previous post we learn how to track active users location on google map with the help of PHP and google map API.
Today we will see how to insert Hindi font into MySQL database.
we will complete us this task into three steps.
in the very first step we will create a database with the name of “hindi_fonts“, and also create a database table “user_details” which have to column the first one is id and another one is user_name.
in the second step, we will insert the user’s name (Hindi font) into the database.
in the final step, we will fetch all the inserted record and shows in HTML table format.
Create Database
CREATE DATABASE hindi_fonts CHARACTER SET utf8 COLLATE utf8_general_ci; USE hindi_fonts; CREATE TABLE `user_details` ( `user_name` varchar(200) COLLATE utf8_general_ci NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
index.php
<!DOCTYPE html> <html> <head> <title></title> `<meta charset="UTF-8">` </head> <body> <?php if(isset($_POST['submit'])) { $con= mysqli_connect("localhost","root","rootpassword","hindi_fonts"); mysqli_set_charset($con,'utf8'); $qry= "INSERT INTO user_details(`user_name`)VALUES ('".$_POST['user_name']."');"; $result= mysqli_query($con,$qry); } ?> <form method="post" action=""> <input type="text" name="user_name"> <input type="submit" name="submit"> </form> </body> </html>
Fetch.php
<!DOCTYPE html> <html> <head> <title></title> <meta charset="UTF-8">` </head> <body> <h2>Users Information</h2> <table> <tr><td>USER NAME</td></tr> <?php $con= mysqli_connect("localhost","root","rootpassword","hindi_fonts"); mysqli_set_charset($con,'utf8'); $qry="SELECT * FORM user_details;"; $result= mysqli_query($con,$qry); while($row= mysqli_fetch_array($result)) { ?> <tr><td><?php echo $row['user_name']; ?></td></tr> <?php } ?> </table> </body> </html>