I use a simple Insert to save data (word with accents, ñ) of user registration in a mysql table, but when I use this script in local works without issue but when I use in a host, is saved as If encrypted and I don't understand.
PHP
$query = "INSERT INTO usuarios
(user, password, name, lastname, phone, email)
VALUES ('$user','$pass','$name','$lname','$phone','$email')";
$result = mysql_query($query) or die (mysql_error());
Connection With DataBase
require_once 'config.php';
//connecting to mysql
$con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
//selecting database
mysql_select_db(DB_DATABASE);
mysql_query('SET names=utf8');
return $con;
}
My table and database has utf8 and in my HTML FORM I have
<meta charset="utf-8">
And for example, if I insert these data:
$user = 'soldier';
$pass = '1234';
$name = 'Edgar';
$lname = 'Ramírez';
$phone = '234234';
$email = 'soldier@mail.com';
This is a result that was stored in the table:
Table: Users
user | password | name | lastname | phone | email
________________________________________________________________________________________
soldier 1234 Edgar 52616dc383c2ad72657a 234234 soldier@mail.com
And that happens all the time, if a word has ñ or accent, is inserted in the table that way :/
I hope I have explained!
lastname
is obviously changed somehow somewhere.mysql_xx()
functions are considered obsolete. It is strongly recommended to upgrade to either themysqli_xx()
alternatives or the PDO library.