Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to store chinese characters from an html page into oracle database using ajax concept.
Front end : HTML & PHP.
Back end  : Oracle 11G.

Oracle Characteristics:
NLS_LANGUAGE = AMERICAN
NLS_CHARACTERSET = AL32UTF8
NLS_NCHAR_CHARACTERSET = AL16UTF16

The above characteristics cannot be changed.

What I have tried:

when i try to store chinese character using form submit it's storing successfully, if i try to store through ajax i am getting weird characters in the database.

in the ajax page i have added this line:
PHP
header("Content-type: text/html; charset=utf-8");

in the html page added the below line:
HTML
<meta http-equiv="Content-type" value="text/html; charset=utf-8">

i have gone through many stack overflow suggestions but no luck.

please advice me on how to solve this.

Thanks in advance.

Code:HTML Code.

HTML
<html>
<head>
<meta http-equiv="Content-type" value="text/html; charset=utf-8">
<title>Test</title>
<script src="jquery.min.js"></script>
<script>
function addForm()
{
var english=document.getElementById('txt_english').value;
var id=document.getElementById('txt_id').value;
var chinese=document.getElementById('txt_chinese').value;
$.ajax(
{
    type : "POST",
    async: false,
    url :"ajax/ajax_add_form.php",
    data :
    {
    english:english,
    chinese:chinese,
    id:id
    }
}).done(
function(html)
{
        alert(html);

});
}
</script>
</head>
<body>
<input type='text' name='txt_id' id='txt_id' value='' /><br>
<input type='text' name='txt_english' id='txt_english' value='' />                          
<input type='text' name='txt_chinese' id='txt_chinese' value='' /> 
<button type="button" >Click Me!</button> 
</body>
</html>

PHP Code: ajax/ajax_add_form.php

PHP
<?php
header("Content-type: text/html; charset=utf-8");
include("../config.php");
extract($_REQUEST);
$sql=oci_parse($conn,"insert into test(id,english,chinese)values('".$id."','".$english."','".$chinese."')");
oci_execute($sql);
echo "success";
?>
Posted
Updated 30-Nov-16 23:50pm
v2

1 solution

//header("Content-type: text/html; charset=utf-8");
include("../config.php");
extract($_REQUEST);
$sql=oci_parse($conn,"insert into dept(DEPTID,DEPARTMENT,DEPTCHN )values('".$id."','".$english."','".$chinese."')");
oci_execute($sql);
echo "success";
?>

simply check your column name like>DEPTID INTEGER,
DEPARTMENT VARCHAR2(40 BYTE),
DEPTCHN VARCHAR2(75 BYTE)
)
finally you can store chinese character
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900