Wednesday, 18 May 2011

Taking hindi input in PHP

Hey friends this is my first post on PHP.
Wish me Luck and let's see where can I take it up to.


Overview: - We have to take input in Hindi from a PHP page and save it in database and to populate it later on another page.

So guys what we using are as follows.
1.) PHP development tool: - Eclipse
2.) Database: - MySQL 5.0
3.) Database Browser: - MySQL Query Browser 5.0
4.) Designing: - HTML
5.) Server: - Apache 2.0 (XAMPP)
6.) Browser: - Firefox 4.0 Beta
7.) OS: - Microsoft Windows XP

So here we start First of all let’s create a database in name of Hindi_Data


CREATE DATABASE Hindi_Data

Now lets create a table in name of Details

      
CREATE TABLE Details
(
   ID            INTEGER (2)         PRIMARY KEY,
   NAME    VARCHAR (100)   CHARACTER SET UTF8
)



Now let's insert data in table.

 

To see Hindi fonts in MySQL Query Browser

Go to Tools > Options > General Options



Then change Default Font, Data Font and Code Font to "Arial Unicode MS"

Now Execute the INSERT Query and then the following SELECT Query.

SELECT ID, NAME FROM Details d;

Now the PHP and HTML Parts.

Note: - Text Highlighted as RED in the given below code is something that's necessary to meet our requirements...

Connect.php

<?php
// MySQL Server Connection Information
$dbhost = 'localhost';
$dbuser = 'Ank';
$dbpass = 'pass';
$database = "hindi_data";
?>

HindiEntry.php

<html lang="hi">
    <head>
       <title>Hindi Data entry</title>
       <meta http-equiv="Content-Language" content="hi">
       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
            <form name="frm1" method="POST" action="HindiEntry.php">
            <input type="hidden" name="posted" value="true" />
            Enter Hindi Text : <input type="text" name="txt1" size="20" maxlength = "100" />
            <br />
            <input type="submit" name="submit" value="Submit" />
            </form>
            <?php
               include ("Connect.php");
            if (isset($_POST['posted']))
            {
               
            $Connect = mysql_connect($dbhost, $dbuser, $dbpass) or
            die("Cannot connect to the server");
            mysql_select_db ($database, $Connect) or
            die ("Cannot find database");

            $txtinput = $_POST['txt1'];

            $InsertQuery = "INSERT INTO Details (Name) VALUES ( '" . $txtinput . "')";
            mysql_query ($InsertQuery, $Connect);

                mysql_close($Connect);
                }
               ?>
    </body>

  



Now HindiView.php

<html lang="hi">
    <head>
        <title>Hindi Data entry</title>
        <meta http-equiv="Content-Language" content="hi"/>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    </head>
    <body>
        <?php
            include ("Connect.php");
            $Connect = mysql_connect($dbhost, $dbuser, $dbpass) or
            die("Cannot connect to the server");
            mysql_select_db ($database, $Connect) or
            die ("Cannot find database");

            $SelectQuery = "SELECT ID, NAME FROM details ORDER BY ID";
            $QueryResult = mysql_query($SelectQuery, $Connect);

            echo "<table border='1'>";
            while($Hindi_Data = mysql_fetch_row($QueryResult))
            {
                echo "<tr><td>" . $ Hindi_Data[0]. "</td><td>" . $ Hindi_Data[1] . "</td></tr>";
            }
            echo "</table>";
            mysql_close($Connect);
        ?>
    </body>
</html>



So friends if have any doubts / problems then do ask.

--AnkDroid--

2 comments:

  1. The HindiView.php code is not running correctly

    ReplyDelete
  2. What problem are u getting?

    ReplyDelete

Terms and Conditions Old School Tic Tac Toe

Terms & Conditions By downloading or using the app, these terms will automatically apply to you – you should make sure therefore that y...