我创建了一个用户可以填写的表单,它会检查用户是否正确插入了电子邮件.
INSERT将数据存入数据库.因此,当我尝试在PHP文件中添加表单时出现问题,因此我可以发出警报或在同一页面上向用户提供错误消息.我开始得到这个错误:
未声明HTML文档的字符编码.如果文档包含US-ASCII范围之外的字符,则文档将在某些浏览器配置中使用乱码文本进行渲染.必须在文档或传输协议中声明页面的字符编码.
所以我试图通过恢复到旧版本来恢复它,我不得不剪切和粘贴几段代码,但没有太复杂.由于一些奇怪的原因,我仍然得到这个错误.当然,我在Stackoverflow上检查了这个问题的相似主题,但没有一个答案让我更进一步.例如meta,在页面的标题中添加信息,我还创建了一个这样的PHP标题:header('Content-type: text/html; charset=utf-8');之后我读了一些关于这个错误的文章,但没有人帮我解决这个问题.
这是我的代码示例.这是我收到错误的页面:
<?php
include_once('credentials.php');
mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
include_once('functions.php');
$apples = sanitize($_POST['Apple']);
$oranges = sanitize($_POST['Orange']);
$melons = sanitize($_POST['Melon']);
$pears = sanitize($_POST['Pear']);
$strawberries = sanitize($_POST['Strawberry']);
$grapes = sanitize($_POST['Grape']);
if($_POST['Grape'] == 'Yes')
{ $grapes = 1; }
else
{ $grapes = 0; }
$blueberries = sanitize($_POST['Blueberry']);
if (checkStrawberries($strawberries) == true) {
mysql_query(" INSERT INTO tablename (Name, Weight, Color, Ripeness, Age, Origin, Destination)
VALUES ('$apples', '$oranges', …Run Code Online (Sandbox Code Playgroud)