Accent problems with PHP and Mysql

Asked

Viewed 346 times

0

I am making a PHP form, in which I used a javascript in a combo.

So when I select the first select, the second opens different data depending on what you select first. Until then ok, it works.

Example of two different options, which I used in dynamic combobox:

var groups=document.banquinho.oferta.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option("--")

group[1][0]=new Option("Erro na parametrização da regra de negocios")

group[2][0]=new Option("BA/SE - Pendência comercial")
group[2][1]=new Option("CO/N - Pendência comercial")
group[2][2]=new Option("CPF não confere com o nome do cliente")
group[2][3]=new Option("Data de nascimento digitada não confere com o CPF do      cliente")
group[2][4]=new Option("Documento não cadastrado no Serasa")
group[2][5]=new Option("Faixa etária não permitida para habilitação")

It works normal, but then when I go to enter in the database, I need to enter the code, equivalent to each offer of this combo.

Since I don’t know how to assign a numerical value to it directly in Javascript (maybe it’s even easier), I ended up doing a kind of trick to assign value in PHP.

$queryComp = "SELECT CodComplemento FROM test.tbl_complemento WHERE Complemento like '%$complemento%' ";
$resultComp = mysqli_query($link, $queryComp);
$numComp = mysqli_num_rows($resultComp);

if ($numComp > 0) 
{
    $dataComplemento    =   mysqli_fetch_array($resultComp);
    $varComplemento     =   $dataComplemento['CodComplemento'];
}
else 
{  
    $message  = 'Complemento não encontrado -> Invalid query: ' . mysql_error()  . "\n";
}

Where the Complement, is the value that is inside that matrix up there, as for example the value: "BA/SE - Trade pending".

There when I select in the combo, a sentence without accent, he finds it straight and assigned the value, but when it has accent does not work! I echo the query and the right accents appear and if I run it directly in the bank, it works.

The bank is in latin1_swedish_ci and the form in utf-8, I changed the table and the bank to utf-8 and nothing, for Latin again and nothing, I changed the form to "charset=ISO-8859-1" and nothing... I did everything that came to mind and I don’t know why it’s not rolling.

I went up the data in the table by means of that script, LOAD, which we called csv and it worked, the accents appear correctly. But when will I insert the word "no" by the form, for example, it is incorrect.

Can someone help me?

  • Include the error returned by the Database.

  • Returns no error, it simply does not find in the database and assigns no value. $numComp = mysqli_num_rows($resultComp) is zero. Something else: When I enter the word not, for example, it is incorrect in the bank.

  • could you make the BD scheme available? I think Voce needs to model the bank better to simplify its problem

  • You can leave the bank as latin_1 and the rest as utf-8... at least here worked perfectly.

  • have you tried using the PHP function utf8_encode($value) or html_entity_decode($value) ?

  • I can’t log in with the other login, but it’s me. I tried these functions and they didn’t work @Ivanferrer. I will have to build the database for use on the server. The database is already structured in access, I have to use the same schema in mysql:(. I think it’s some kind of structural problem, I’m going to put it back together since it’s small, to test it again.

  • change latin1_swedish_ci to utf8_general_ci

Show 2 more comments

1 answer

1


Try this and see if it solves the problem:

ALTER DATABASE `sua_base` CHARSET = UTF8 COLLATE = utf8_general_ci;
  • 1

    That solved it, thank you very much!

  • If it was helpful to you, tick the green arrow. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.