php:在myadmin数据库中插入特殊字符 [英] php: Insert special characters into myadmin database

查看:143
本文介绍了php:在myadmin数据库中插入特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello stackoverflow的人!

Hello stackoverflow people!

我有一个问题,我没有能够解决3个月的尝试后。在这个网站上有类似的问题,但他们没有给我我需要的结果。

I've got a problem which I haven't been able to solve after 3 months of trying. There are similar problems described on this website, but they didn't give me the result I need.

结果我得到:
点击此处获取结果

结构设置:
点击此处查看结构

我的代码:

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'
                              )
                    " );
}


推荐答案

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

You are sending characters as Unicode, and the fields are in Unicode, but the database connection is not. Use this immediately after connecting:

SET NAMES 'utf8'

这篇关于php:在myadmin数据库中插入特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆