Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysql可以';不显示中文_Php_Mysql_Sql_Character Encoding - Fatal编程技术网

Php mysql可以';不显示中文

Php mysql可以';不显示中文,php,mysql,sql,character-encoding,Php,Mysql,Sql,Character Encoding,当我想在表格中输入一些汉字时 <html> <title> Form </title> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8"/> </head> <body> <div id="wrapper"> <form action="form.php" method="post" accept-

当我想在表格中输入一些汉字时

<html>
<title>
Form
</title>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
</head>
<body>
<div id="wrapper">
<form action="form.php" method="post" accept-charset="UTF-8" >
<p>Input: <input type="text" name="input1" /></p>
<input type="submit" value="Submit" />
</form>


</div>
</body>
</html>`

形式
输入:

`
以及form.php:

<?php
header('Content-Type: text/html; charset=utf-8');

define('DB_NAME','form1');
define('DB_USER','root');
define('DB_PASSWORD','');
define('DB_HOST','localhost');

$link= mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);

if (!$link){
    die('could not connect server'.mysql_error());  
} 

$db_selected = mysql_select_db(DB_NAME,$link);

if(!$db_selected){
    die('Cannot connect'.DB_NAME.': '.mysql_error());
}

$value=$_POST['input1'];

$sql="INSERT INTO form (input1) VALUES ('$value')";

if (!mysql_query($sql)){
    die('Error: '.mysql_error());
}


mysql_close();
header("Location: form.htm");
?>

您在数据库连接后是否尝试使用此行

mysql_query("SET NAMES utf8");
你可以试试这个

mysql_set_charset('utf8', $link);
像这样

<?php
header('Content-Type: text/html; charset=utf-8');

define('DB_NAME','form1');
define('DB_USER','root');
define('DB_PASSWORD','');
define('DB_HOST','localhost');

$link= mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
mysql_set_charset('utf8', $link);
if (!$link){
    die('could not connect server'.mysql_error());  
} 
...
...
可能重复的可能重复的可能重复的不使用
mysql.*
接口;切换到PDO或mysqli*
是一个“html实体”;《代码》是如何编写的消失?让我们看看将字符串放入表中并将其取出的SQL。