duanpu2272 2016-04-28 13:22
浏览 16

PHP,MYSQL INSERT INTO umlauts,如ä,ü,ö

I have a problem. Im sitting on that problems since hours and I cant find any solution.

I changed Database Character Set and Collation to UTF8 - not working.

When I insert normal letters its working but if one umlaut is in the input, the input is empty in database.

Code:

if(isset($_POST['submitSecurityQuestions'])){

$securityQuestion1 = $_POST['securityQuestion1'];
$securityQuestion2 = $_POST['securityQuestion2'];
$securityAnswer1 = $_POST['securityAnswer1']);
$securityAnswer2 = $_POST['securityAnswer2'];

if(empty($securityAnswer1) || empty($securityAnswer2))
{
    $msg = "Du hast nicht alles ausgefüllt!";
} else {
    if($securityAnswer1 < '4' || $securityAnswer2 < '4') {
        $msg = "Du musst mindestens 4 Zeichen eingeben!";
    } else {
        mysql_query("UPDATE users SET securityQuestions = '1' WHERE id = '".$user->id."' LIMIT 1") or die(mysql_error());                   
    mysql_query("INSERT INTO `users_securityquestions` (`securityQuestion1`, `securityQuestion2`, `securityAnswer1`, `securityAnswer2`, `createdTime`, `createdIP`, `createdUserAgent`, `active`, `userID`) VALUES ('".$securityQuestion1."', '".$securityQuestion2."', '".$securityAnswer1."', '".$securityAnswer2."', '".$time."', '".$ip."', '".$user_agent."', '1', '".$user->id."');") or die(mysql_error());
        header('location:'.$_SERVER['PHP_SELF']);
    }
} }

I also tryed that Filter:

function FilterText($str) {
    if(get_magic_quotes_gpc()){ $str = stripslashes($str); }
    $str = preg_replace(array('/\x{0001}/u','/\x{0002}/u','/\x{0003}/u','/\x{0005}/u','/\x{0009}/u'),' ',$str);
    $str = mysql_real_escape_string($str);
    return $str;
}

How can I insert Umlauts like ä or ü into database? I'm using MySQL.

Thanks!

  • 写回答

3条回答 默认 最新

  • dongtang2376 2016-04-28 13:32
    关注

    Try running this query before your inserts:

    SET NAMES utf8;
    

    This will tell the MySQL server that the incoming data is also utf8 encoded.

    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)