当我点击我的表单的提交按钮时,出现以下错误消息:
没有声明HTML文档的字符编码。如果文档包含US-ASCII范围之外的字符,那么在某些浏览器配置中,文档将以乱码文本呈现。页的字符编码必须在文档或传输协议中声明。
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;
?>
我不知道我的代码有什么问题。请帮帮我。
Your initial page is a complete HTML page containing a form, the contents of which are posted to insert.php when the submit button is clicked, but insert.php needs to process the form's contents and do something with them, like add them to a database, or output them to a new page. Your current insert.php just outputs the contents of the title field, so your browser tries to interpret that as an HTML page, and fails, obviously, because it isn't valid HTML (i.e. it isn't contained in an 'HTML' tag, etc.).
php需要输出必要的HTML,并在其中某处插入表单数据。
例如:
<?php
$title = $_POST["title"];
$price = $_POST["price"];
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
echo '<title>';
echo $title;
echo '</title>';
echo '</head>';
echo '<body>';
echo 'Hello, world.';
echo '</body>';
?>
Your initial page is a complete HTML page containing a form, the contents of which are posted to insert.php when the submit button is clicked, but insert.php needs to process the form's contents and do something with them, like add them to a database, or output them to a new page. Your current insert.php just outputs the contents of the title field, so your browser tries to interpret that as an HTML page, and fails, obviously, because it isn't valid HTML (i.e. it isn't contained in an 'HTML' tag, etc.).
php需要输出必要的HTML,并在其中某处插入表单数据。
例如:
<?php
$title = $_POST["title"];
$price = $_POST["price"];
echo '<html xmlns="http://www.w3.org/1999/xhtml">';
echo '<head>';
echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
echo '<title>';
echo $title;
echo '</title>';
echo '</head>';
echo '<body>';
echo 'Hello, world.';
echo '</body>';
?>