I have a PHP script which takes in POST params and saves them to a database. The script itself works fine, but if any of the POST params contains hebrew text, I get the following error:
error number 1366: Incorrect string value: '\xF2\xE9\xE3\xE5 \xF7...' for column 'Name' at row 1
The column definition is:
`Name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
The table and the database are also defined as CHARACTER SET utf8 COLLATE utf8_general_ci. Also, stripslashes is executed on the query before it is run.
The curious thing is that the original column definition did not include CHARACTER SET and COLLATE. When it didn't have those, running the same insert statement with hebrew characters through MySQL Workbench got me the same error - but only as a warning. Then I added the CHARACTER SET and COLLATE params to the column definitions, rebuilt the table and ran my queries again though Workbench - all good.
... but the PHP script still returns this error.
Does anyone know why this is happening? Can I suppress warnings in the SQL statement itself so as just to ignore these?
EDIT: PHP code:
function dbConnect() {
global $host, $user, $pwd, $db, $MYSQL_ERRNO, $MYSQL_ERROR;
$dbConn = mysql_connect($host,$user,$pwd);
if (!$dbConn) {
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = "Could not connect to $host";
return false;
} else if ($db && !mysql_select_db($db)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return false;
} else {
return $dbConn;
}
}
$link = dbConnect() or die(sql_error());
$query="INSERT INTO maillist (Name,LastName,email,status,sex,City,date_added) VALUES (N'".filter_var($_POST['Name'], FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)."',N'',N'".filter_var($_POST['email'], FILTER_SANITIZE_EMAIL)."','0',N'',N'',CURDATE())";
$query = stripslashes($query);
$result = mysql_query($query,$link) or die(sql_error());