Problems with accents with PHP and MySQL

0

I'm doing 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, it works.

Example of two different options, which I used in the 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 when I insert it into the database, I need to insert the code, equivalent to each offer of this combo.

As I do not know how to assign a numeric value to it directly in Javascript (maybe it's even easier), I ended up doing a bit of a trick to attribute 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 above, as for example the value: "BA / SE - Commercial pendency".

Then when I select in the combo, a sentence without an accent, it finds it right and assigned the value, but when it has accent does not work! I echo the query and appear the accents straight and 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, to latin again and nothing, I changed the form to "charset = ISO- 8859-1 " and nothing ... I did everything that came to mind and I do not know why it's not happening.

Upload the data in the table through that script, LOAD, which we call csv and worked, appear the accents correctly. But when I enter the word "no" by the form, for example, it is incorrect.

Can anyone help me?

    
asked by anonymous 13.07.2015 / 22:30

1 answer

1

Try this and see if it solves the problem:

ALTER DATABASE 'sua_base' CHARSET = UTF8 COLLATE = utf8_general_ci;
    
15.07.2015 / 20:26