The character encoding of the HTML document was not declared

xing picture xing · Aug 17, 2012 · Viewed 281.8k times · Source

When I click on my form's submit button the following error message appears:

"The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol."

insert.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>

insert.php:

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

  echo $title;
 ?>

I dont know where is the problem in my code. Please help me.

Answer

Krishan Gopal picture Krishan Gopal · Oct 10, 2012

Add this as a first line in the HEAD section of your HTML template

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