Unicode Data with PHP 5 and MySQL 4.1

Naseer Ahmad

I am Naseer Ahmad Mughal from Islamabad (Pakistan). I have been working as a Manager Development at SyntecX from last 4+ years, and its my passion to learn new things and implement them as a practice. I am also work as freelancer as well as a volunteer web development expert who loves to learn through innovative ideas and inspiration. You can find me online at LinkedIn & Twitter

You may also like...

7 Responses

  1. Naseer Ahmad says:

    Hi Dieter,
    here is the independent working code for you especially.

    <?php
    
    	$server = 'localhost';
    	$username = 'root';
    	$password = 'password here';
    	$database = 'db-name';
    
    	$con = mysql_connect($server, $username, $password);
    	$link = mysql_select_db($database);
    	mysql_query("SET NAMES 'utf8'");
    
    	if ( !empty ( $_POST['ta'] ) ) 
    	{
    		$test = mysql_query("INSERT INTO document (id, unicodeText) VALUES (NULL, '".$_POST['ta']."');", $con);
    	}
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    	<title>Test for UTF-8</title>
    </head>
    <body>
    	<p> List all records </p>
        <div>
    	<?php 
    		$result = mysql_query("SELECT id, unicodeText FROM document", $con);
    		while ($return = mysql_fetch_array($result))
    		{
    			print $return['id'] . ' - > ' .$return['unicodeText'] . '<br />';
    		}
    		mysql_free_result($result);
    	?>
        </div>
    	<p>Posted: <?php echo $_POST['ta'];?></p>
    	<form enctype="multipart/form-data" method="post" action="">
        <fieldset>
    	    <textarea name="ta" cols="35" rows="3"></textarea><br />
        	<input type="submit" value="Insert New" />
        </fieldset>
    	</form>
    </body>
    </html>
    

    If you still facing problem i will help you out. In which language you want to implement unicode?

    regards, Naseer

  2. Naseer Ahmad says:

    yes you are right, actually its not a independent code. this code is dependent upon classes. Later in a day, i will post the new code i.e. easy to understand and implement.

    Regarding your second point, comments form, yes i have seen that and also fix it today,

    Regards, Naseer

  3. Naseer Ahmad says:

    Hi Dieter,

    thanks for concern regarding code.
    before using this code, it assumes that you already have one row record) in database having ID = 1. So when you post the values in textarea it will same under that id.

    Its not any follow up post. Plz try this before adding one sample record in database.

    I hope you understand this, if not, feel free to contact back.

  4. Dieter says:

    Sorry Naseer, i changed your name to Andrew … 🙂

    Actually i got it. The code you supplied doesn’ t work out of the box. There are a lot of missmatching lots of ‘ and ` and ” in the wrong place. Don’ t know why. I fixed that, but missed one or two. Thus i wasn’ t able to submit a new row. Maybe you have a unicode problem?

    By the way, you should fix your comment form. Long lines are invisible as you can see here . I use Firefox 2.0.0.6.

    Regards Dieter.

  5. Dieter says:

    Naseer (Andrew),

    you wrote:

    Lines 4-6 update a row in the database with the Unicode data we send through the form. (Make sure to have some sample data in row 1 of the database when you test this code)

    What does this mean? Is this post a follow up post of a post i haven’ t red or i am missing something?

  6. Naseer Ahmad says:

    Wassalam Mike, could you plz provoide me the online demo link where i can check the output.

    Regards,
    Naseer

  7. michael yohannes says:

    Hello, Mr. Mughal I have found your script very helpful. Thank you.
    I am working my senior project in computer science field. I am an
    Ethiopian. Africa; east Africa specifically. We don’t have much help
    except finding such guys like you. We are living in the third
    countries. No educational facilites at all. But, thanks to the
    internet we are alive.

    Mr. Mughal, I can simply guess that you are busy. However, I am also
    sure that you want to help others. Specially in your field. My point
    is I developing a website for the project and it is almost depend on
    my language;Amharic. We use Ethiopic font.

    My problem is to use unicode to put and read data to/from the mysql
    4.1 db. I am using php 5. I have left only with 15 days but I am
    stacked. I tried your script but I think I don’t know how to handle
    it. So, please I need your help. Can you send me something that can
    help me. Thank u. Call me Mike. Aselam Alekum.

Leave a Reply to Naseer Ahmad Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.