5

I am having problems making mydatabase table show Latin caracters. (ã,õ,á,é,í,…). I am using WAMP server with Apache 2.4.9 and MySQL 5.6.17.

I have a simple form that I created in HTML and I have a PHP code witch runs a query and creates the account. Here is the PHP code:

include('config.php'); //My database data for connection

if(isset($_POST['submit'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];

    $query = "INSERT INTO account SET username = '".$username."', password = PASSWORD('".$password."'), email = '".$email."'";
    $execute_query = mysqli_query($connection, $query);
    if($execute_query) { 
        //Creates the account
    }
    else { 
        //If an error occures
    }
}

Now for example, I create an account with:

Username: Luís
Password: 1234
E-mail: somemail@mail.com

When I go check the Table it shows the account created but the username shows LuÃs instead of Luís.

Things I have tried:

Creating a DataBase and Table with:
utf8_general_ci
utf8_unicode_ci
utf8mb4_general_ci
utf8mb4_unicode_ci
latin1_swedish_ci

None of them worked, it always shows that à instead of í.

Giacomo1968
  • 58,727

1 Answers1

3

I have fixed my problem with the query "SET NAMES utf8".

include('config.php'); //My Database data for connection.
//Connection set with $connection = mysqli_connect($mysql_host, $mysql_user, $mysql_pass, $mysql_db)

if(isset($_POST['submit'])) { $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email'];

$connection->query("SET NAMES utf8"); //FIXED (Gets $connection from config.php and runs the query "SET NAMES utf8")
$query = "INSERT INTO account SET username = '".$username."', password = PASSWORD('".$password."'), email = '".$email."'";
$execute_query = mysqli_query($connection, $query);
if($execute_query) { 
    //Creates the account
}
else { 
    //If an error occures
}

}

Thank you @Giacomo1968 for trying to help me in their answer, after all I had no problems with my database table.

My database and table were set with CHARSET=utf8 and COLLATE=utf8_unicode_ci.

Giacomo1968
  • 58,727