DEV Community

joshua-brown0010
joshua-brown0010

Posted on

How to insert Hindi text in MySQL database using php?

In this article, we will learn how we can insert data in Hindi font using the php and MySQL. In the first step, we will create a database with the name of “Hindi fonts” and also create a database table with the name “User”. The table will contain the two columns id and name. In the second step, we will insert the name in Hindi format and then we will fetch the data from the database and then display it in the HTML table.

Create database

CREATE DATABASE hindi_fonts

          CHARACTER SET utf8

         COLLATE utf8_general_ci;

USE hindi_fonts;

CREATE TABLE “user (

   ‘name’ varchar(255) COLLATE utf8_general_ci NOT NULL

)
Enter fullscreen mode Exit fullscreen mode

Index.php

<!DOCTYPE html>

<html>

<head>

               <title></title>

               <meta charset="UTF-8">

</head>

<body>

<?php

if(isset($_POST['submit']))

{

               $conn= mysqli_connect("localhost","root","password","hindi_fonts");

               mysqli_set_charset($conn,'utf8');

               $query= "INSERT INTO user(`name`)VALUES ('".$_POST['name']."');";

               $result= mysqli_query($conn,$query);



}

?>

<form method="post" action="">

<input type="text" name="name">

<input type="submit" name="submit">

</form>

</body>

</html>
Enter fullscreen mode Exit fullscreen mode

Read more

Top comments (0)