Android Question UTF8 (again)

KMatle

Expert
Licensed User
Longtime User
Though I have defined all my MySql tables as utf8_unicode_ci and even my php script with "SET CHARACTER SET utf8" today I recognized characters that wont be stored correctly.

Working:

French & German characters (like äöüß or êéè)

Not working:

Symbols of the Android keyboard (like heart, square, circle, etc.) using a Samsung S4

I don't get it. Can anyone give me a hint?
 

KMatle

Expert
Licensed User
Longtime User
Nothing special.
B4X:
mysql_query("SET CHARACTER SET utf8");
case "NewChatMess":
        $from = $_GET["From"];
        $to = $_GET["To"];
        $message = $_GET["Message"];
       
        $q = mysql_query("Insert into messages (mfrom, mto, message) VALUES ('$from', '$to', '$message')");
        print json_encode ("Sent"); 

case "GetMess":
        $from = $_GET["From"];
        $to = $_GET["To"];
       
        $q = mysql_query("SELECT message FROM messages where (mfrom= '$from' and mto = '$to') or (mfrom= '$to' and mto = '$from') order by t ");
        $rows = array();
        while($r = mysql_fetch_assoc($q))
        {
            $rows[] = $r;
        }
        print json_encode($rows); 
        break;
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
LOOK HOW I MAKE
i have a php with pass and i send from my app the link+pass
if is correct make a query on db and return on json

MY PHP
B4X:
<?
if (isset($_REQUEST['Senha'])){
$Senha=trim($_REQUEST['Senha']);


if($Senha=="wdllwoqmwkkoe"){


$databasehost = "77.77.77.77";
$databasename = "mydatabasename";
$databaseusername ="root";
$databasepassword = "lalala";

$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
$query = file_get_contents("php://input");
$sth = mysql_query($query);

if (mysql_errno()) {
    header("HTTP/1.1 500 Internal Server Error");
    echo $query.'\n';
    echo mysql_error();
}
else
{
    $rows = array();
    while($r = mysql_fetch_assoc($sth)) {
        $rows[] = $r;
    
    }
    print json_encode($rows);
}
}
else{
echo "Sem acesso!";
}

}


else {
  echo "Acesso Negado";
}
?>

HOW TO CALL ON THE APP
B4X:
  Sub ExecuteRemoteQuery(query As String, JobName As String)
        Dim jobs As HttpJob
        jobs.Initialize(JobName, Me)
        jobs.PostString("http://www.MYSITEORIP.com.br/queryachouganhou.php?Senha=wdllwoqmwkkoe", query)
    End Sub

    'QUERY DE VERIFICAÇÃO  DE VERSÃO
    Sub verifica_appversao_app
        ExecuteRemoteQuery("SELECT * FROM versao WHERE Versao > '"&versionString&"'"  , versaoasda)
    End Sub


Sub JobDone (Job As HttpJob)
    If Job.Success Then
        Dim respostadoservidor As String
        respostadoservidor = Job.GetString

    Select Job.JobName

        Case "versaoasda"
       mface.Initialize 'map
        parserface.Initialize(respostadoservidor)   '   parserface As JSONParser
        listaface.Initialize 'list
        listaface = parserface.NextArray  'list = parse
        mface = listaface.Get(0) 'map get list
    
        id = mface.Get("Version") 'my collun on my db


    

        End Select
    

    
    Else
  
        Job.Release

        End If
    End If
Job.Release
End Sub


this code insert with utf8 make a select with utf8 normal working
@DonManfred helped my on this
 
Last edited:
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
why dont block this on the app ?
dim teclado as IME
teclado.SetCustomFilter(nome, nome.INPUT_TYPE_TEXT, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 .")

dont alow user put ;) :) ;( :( / * : ; ] [ etc...

and on the php too can use

mysql_set_charset('utf8'); 'charset

mysql_query("SET NAMES 'utf8'") 'for querys

header('Content-Type: text/html; charset=UTF-8'); 'header
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
@Klaus Matle the code i have posted works with characters fine

i tryed to make a insert with 3$#;:)}(

and no problems select and insert

B4X:
Sub querycadastra   
    Private mes As Int
    mes = spmes.SelectedIndex +1
    fn = "3$#;:)}("
    ExecuteRemoteQuery("INSERT INTO usuarios (StatConta, NickName, SocID, SocNet, FirstName, LastName, CompName, Gender, DataNasc, Email, Locale, CamFotoPerfil, Country, City) VALUES ('2', '"&fn&"' , '"&idsocial&"', '"&redesocial&"' , '"&fn&"' , '"&ln&"' , '"&cn&"' , '"&sexo&"' , '" &spano.SelectedItem&"-"&mes&"-"&spdia.SelectedItem& "' , '"&edemail.Text&"' , '"&locale&"' , '"&imgsocial&"' , '"&sppais.SelectedItem&"','"&edcidade.Text&"')" , resultadodocadastro)
    End Sub
 

Attachments

  • Sem título.png
    Sem título.png
    159.5 KB · Views: 205
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Upvote 0

JUAN CARLOSORDOÑEZ

Member
Licensed User
Longtime User
Gracias Douglas.

Encontré esta solución:
cadena=cadena.Replace(" ","_") pero como hago en el código php para que remplace y guarde en la base como debe ser. sin _ ?
 
Upvote 0
Top