【问题标题】:php: Insert special characters into myadmin databasephp:将特殊字符插入 myadmin 数据库
【发布时间】:2012-06-18 15:57:55
【问题描述】:

大家好!

我有一个问题,经过 3 个月的尝试,我无法解决。这个网站上描述了类似的问题,但他们没有给我我需要的结果。

我得到的结果: 删除链接

结构设置: 删除链接

我的编码:

include 'connectiondetails.php';

//making the database connection
dbVerbind();

$str = '<p>€ é í å </p>';

// things i've tried
//$test1 = $_GET['test1'];
//$test2 = htmlspecialchars_decode('<p>€ é í å </p>');
//$test3 = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
//$test4 = htmlspecialchars_decode( $str , ENT_QUOTES);
//$test5 = htmlspecialchars('<p>€ é í å </p>', ENT_QUOTES);
//$test6 = parse_str(html_entity_decode($str), ENT_QUOTES);
//$orig = "<p>€ é í å </p>";
//$a = htmlentities($orig);
//$test7 = html_entity_decode($a);
//$test8 = $_GET['test8'];
//$test9 = htmlentities($str, ENT_QUOTES);
//$test10 = mysql_real_escape_string('€ é í å');

$test1 = $_GET['test1'];
$test2 = $_GET['test2'];
$test3 = $_GET['test3'];
$test4 = $_GET['test4'];
$test5 = $_GET['test5'];
$test6 = $_GET['test6'];
$test7 = $_GET['test7'];
$test8 = $_GET['test8'];
$test9 = $_GET['test9'];
$test10 = $_GET['test10'];

if (empty( $test1 )) {
echo '<p>empty</p>';
}
else {
$results =  mysql_query( "  INSERT INTO insert_test.content (   
                                            test1,
                                            test2,
                                            test3,
                                            test4,
                                            test5,
                                            test6,
                                            test7,
                                            test8,
                                            test9,
                                            test10
                                            )
                    VALUES(     '$test1',
                                '$test2',
                                '".htmlspecialchars('€ é í å')."',
                                '".mysql_real_escape_string('€ é í å')."',
                                '€ é í å',
                                '€ é í å',
                                '$test7',
                                '$test8',
                                '$test9',
                                '$test10'
                              )
                    " );
}

【问题讨论】:

    标签: php mysql insert character


    【解决方案1】:

    您正在以 Unicode 格式发送字符,并且字段是 Unicode 格式,但数据库连接不是。连接后立即使用:

    SET NAMES 'utf8'
    

    【讨论】:

      猜你喜欢
      • 2012-03-24
      • 2020-08-30
      • 2018-02-26
      • 2016-02-18
      • 2021-03-27
      • 2011-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多