Results 1 to 3 of 3

Thread: Opera Browser Non-English Character Insertion Problem into MYSQL

  1. #1
    Join Date
    Aug 2011
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Opera Browser Non-English Character Insertion Problem into MYSQL

    Hello, I try to insert text from JavaScript by using AJAX. I send text to a php file and from there to MYSQL database. I have no problem in isterting text even it has non-English characters in it with IE9, Firefox and Chrome. But in Opera, it inserts some different chars instead of correct non-English chars. Javascript code, with "ö" char being red, from where I make Ajax call is below:
    Code:
    if (document.kosul.bir_defa_dogru_cavabi_buldu.value == "") {
    			var yapilan_ornek = "if deyimi örnek 3"; // bu satır her tamamlamalı örnek için değişecek.
    			var kacincida_dogru_cevabi_buldu = document.kosul.yanlis_secim_sayisi.value.length + 1; // doğruyu kaçıncı seçenekte bulduğu = (yanlış seçim sayısı + 1)
    			var xmlhttp;
    			if (window.XMLHttpRequest) {
    				xmlhttp = new XMLHttpRequest;
    			}
    			else {
    				xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP");
    			}
    			var url = "http://localhost/tez/ornek_tamamlama_bilgisini_vt_gonder.php?hangi_ornek=" + yapilan_ornek +"&kacinci_secimde_dogru_cevabi_buldu="+kacincida_dogru_cevabi_buldu;
    			xmlhttp.open("GET", url, false);
    			xmlhttp.send(null);	
    		}
    PHP code making the DB insertion is below:
    Code:
    <?php  
    session_start();
    if(!session_is_registered(myusername)){
    header("location:main_login.php");
    }
    
    function sqlConnect() {
    	$snc1 = mysql_connect ("localhost","root","*****");
    	$snc2 = mysql_select_db ("bote");
    	mysql_query ("SET NAMES 'latin5'"); // Türkçe harfleri içeren karakter setine geçiliyor.
    	$sncDeger= $snc1 and $snc2;
    	return $sncDeger;}
    	
    sqlConnect();
    	if (sqlConnect()){
    		$giristen_gelen_ogrenci_no = $_SESSION['username'];
    //		$hangi_tamamlamali_ornek = "if deyimi 1. tamamlamalı örnek";
    		$tsg = date('d.m.Y - H:i:s');
    //		if (mysql_query("INSERT INTO tamamlamali_ornek_bilgileri (id, hangi_tamamlamali_ornek, tsg) VALUES ('$giristen_gelen_ogrenci_no', '$hangi_tamamlamali_ornek', '$tsg')")) {
    
    		if (mysql_query("INSERT INTO tamamlamali_ornek_bilgileri (id, hangi_tamamlamali_ornek, kacinci_secimde_dogruyu_buldu, tsg) VALUES ('$giristen_gelen_ogrenci_no', '".$_GET["hangi_ornek"]."', '".$_GET["kacinci_secimde_dogru_cevabi_buldu"]."','$tsg')")) {
    			echo "<p>Bilgiler veritabanına eklenmiştir.";
    		} 
    		else { 
    			echo "Bilgiler eklenemedi...";            
    		}
    	}
    	else {
    		echo "Bağlantı Kurulamadı...";
    	}
    
    ?>
    "if deyimi örnek 3" is the right text inserted into the DB with IE9, Firefox and Chrome.
    "if deyimi örnek 3" is the wrong text inserted into the DB with Opera.
    MYSQL DB I use is configured to handle non-English chars correctly according to my knowledge.
    I will appreciate your valuable helps.
    Last edited by tuffy; 09-12-2011 at 10:11 AM.

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    Does it help to set the character encoding to UTF-8 on the page that is sending the AJAX request?
    Code:
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
    If that doesn't work, there are two functions called utf8_encode() and utf8_decode() which encode and decode data in utf-8 respectively.

    http://us2.php.net/manual/en/function.utf8-encode.php
    http://us2.php.net/manual/en/function.utf8-decode.php
    - Josh

  3. The Following User Says Thank You to JShor For This Useful Post:

    tuffy (09-12-2011)

  4. #3
    Join Date
    Aug 2011
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Setting the character encoding to UTF-8 on the page that is sending the AJAX request did not solve the problem. I will read the articles you advised. Thank you.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •