I’m trying to send userdata to mysql database using php. I want username to be cyrillic, and when i manually type the username in database, it is displayed correctly. But when I pass the data to database it`s stored like “Грумінг”
Here is file that proccess the registration of users: reg_query.php
<?php
session_start();
header('Content-Type: text/html; charset=utf-8');
require_once __DIR__ . "/database/pdo.php";
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$password = md5($password);
$sql = "SELECT username FROM `users` WHERE username='{$username}'";
$result = mysqli_query($con,$sql) or die("Query unsuccessful") ;
if (mysqli_num_rows($result) > 0) {
header("Location: login.php?msg=failed");
} else {
$sql = "INSERT INTO `users` (`username`, `password`,`email`) VALUES (:username, :password, :email)";
$params = [
"username" => $username,
"password" => $password,
"email" => $email,
];
$prepare = $pdo->prepare($sql);
$prepare->execute($params);
$pdo->lastInsertId();
$lastInsertId=$pdo->lastInsertId();
$_SESSION['login'] = true;
$_SESSION['username']=$username;
$_SESSION['password']=$password;
header("Location: /cabinet.php");
}
?>
Here is connection file: pdo.php
<?php
$host = "host";
$user = "user";
$password = "password";
$db_name = "db_name";
$pdo = new PDO("mysql:host=$host; dbname=$db_name", "$user", "$password");
$con = mysqli_connect($host, $user, $password, $db_name);
$con->set_charset("utf8mb4");
?>
i tried to add header(‘Content-Type: text/html; charset=utf-8’);
to the reg_query.php but it did not help