未声明 HTML 文档的字符编码

新手上路,请多包涵

当我单击表单的提交按钮时,会出现以下错误消息:

未声明 HTML 文档的字符编码。如果文档包含 US-ASCII 范围之外的字符,则文档将在某些浏览器配置中呈现乱码。页面的字符编码必须在文档或传输协议中声明。

插入.html:

 <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>insert page</title></head>
    <body>
    <h1> Insert Page </h1>
        <form action="insert.php" method="post"  enctype="application/x-www-form-urlencoded" >
         <p>Title:<input type="text" name="title" size="40" /></p>
         <p>Price:<input type= "text" name="price" size="40" /></p>
         <p><input type="submit" value="Insert" />
         <input type="reset" value="Reset" /></p>
        </form>
    </body>
</html>

插入.php:

 <?php
    $title = $_POST["title"];
    $price = $_POST["price"];

    echo $title;
?>

我不知道我的代码中的问题在哪里。请帮我。

原文由 xing 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 401
1 个回答

将此添加为 HTML 模板的 HEAD 部分的第一行

<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">

注意:如果 <head> 和这些元行之间的任何行(即使是注释)问题仍然存在,因此请确保在 <head> 之后直接添加元行

原文由 Krishan Gopal 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题