%20an%20eine%20Datenbanktabelle%20in%20PHP%2FMySQL.png)
Ich habe Probleme, in meiner Datenbanktabelle lateinische Buchstaben anzuzeigen. (ã, õ, á, é, í, …). Ich verwende einen WAMP-Server mit Apache 2.4.9 und MySQL 5.6.17.
Ich habe ein einfaches Formular, das ich in HTML erstellt habe, und einen PHP-Code, der eine Abfrage ausführt und das Konto erstellt. Hier ist der 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
}
}
Jetzt erstelle ich beispielsweise ein Konto bei:
Username: Luís
Password: 1234
E-mail: [email protected]
Wenn ich die Tabelle überprüfe, wird das erstellte Konto angezeigt, aber der Benutzername zeigtLuísanstattLuis.
Dinge, die ich versucht habe:
Creating a DataBase and Table with:
utf8_general_ci
utf8_unicode_ci
utf8mb4_general_ci
utf8mb4_unicode_ci
latin1_swedish_ci
Keiner von ihnen hat funktioniert, es zeigt immer, dassAanstattich.
Antwort1
Ich habe mein Problem mit der Abfrage „SET NAMES utf8“ behoben.
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
}
}
Danke@Giacomo1968 für den Versuch, mir bei seiner Antwort zu helfen, schließlich hatte ich keine Probleme mit meiner Datenbanktabelle.
Meine Datenbank und Tabelle wurden mit CHARSET=utf8
und festgelegt COLLATE=utf8_unicode_ci
.