Jump to content

[SOLVED] input chinese character into mysql


sungpeng

Recommended Posts

<?php

if($_POST[action]=="Submit")
{

include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/config.php");

$loginname=$_POST["loginname"];


$insert_student=mysql_query("insert into users (loginname) values ('$loginname'");

?>



}else{ ?>




<html>

<head>
<title></title>



</head>

<body>

                 

                     <table width="400" align="center">
                    <br> <form name="form" action="<?php echo "$PHP_SELF"; ?>" method="post">
                      

                         
                        <tr> 
                          <td width="35%">Loginname</td>
                          <td><input type="text" name="loginname" size="25"></td>
                        </tr>
                        

                         

                        <tr> 
                          <td align="center" colspan="2"><input type="submit" name="action" value="Submit"></td>
                        </tr>
                      </table>
                    </form>




          
</body>

</html>
<?php 
}
?>
    

 

Hi checking when I input chinese character into "loginname" field using the above code. The chinese character turn out not able to read. Is there a special code for input chinese character?

Link to comment
Share on other sites

What kind of encoding are you using for the database and the connection to that database? What encoding are the individual tables? If you are not using UTF-8 it may not be supported.

Note: that UTF-8 does not yet support the full implementation of standard chinese characters.

Link to comment
Share on other sites

<?

$hostname = "localhost";
$username = "hello";
$password = "fefa";
$dbName = "sgfai_property"; 
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database"); 
mysql_select_db("$dbName") or die("Unable to select database"); 

?>

 

like say I need to insert this 级搜索 into mysql, it will turn out character that cannot read.

Link to comment
Share on other sites

<?php

if($_POST[action]=="Submit")
{

include ("".$_SERVER['DOCUMENT_ROOT']."/housing/includes/config.php");

$loginname=$_POST["loginname"];


$insert_student=mysql_query("insert into users (loginname) values ('$loginname'");

?>



}else{ ?>




<html>

<head>
<title></title>



</head>

<body>



                    <table width="400" align="center">
                   <br> <form name="form" action="<?php echo "$PHP_SELF"; ?>" method="post">



                       <tr> 
                         <td width="35%">Loginname</td>
                         <td><input type="text" name="loginname" size="25"></td>
                       </tr>




                       <tr> 
                         <td align="center" colspan="2"><input type="submit" name="action" value="Submit"></td>
                       </tr>
                     </table>
                   </form>





</body>

</html>
<?php 
}
?>

 

Hi checking when I input chinese character into "loginname" field using the above code. The chinese character turn out not able to read. Is there a special code for input chinese character?

 

 

 

hi,

 

you might want to read this:

http://www.tanzilo.com/2008/10/13/php-mysql-unicode-solution-to-chinese-russian-or-any-language/

 

you will see that you have to make those char encoding queries before inserting things in the database

 

mysql_query("SET character_set_client=utf8", $dbLink); 
mysql_query("SET character_set_connection=utf8", $dbLink); 

 

you can change utf8 on any other char set you want

hope this helps

 

Link to comment
Share on other sites

echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";

mysql_query("SET character_set_client=utf8", $dbLink);
mysql_query("SET character_set_connection=utf8", $dbLink);

$update_pdt=mysql_query("update instructor set description='$_POST[description]' where pid=$_GET[pid]", $dbLink);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.