doutan4831 2018-06-21 01:41
浏览 54

我的网站文字是乱码

I have used header("Content-Type:text/html; charset=utf-8"); & <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> on both html & php parts.

But for the webpage contents displayed , the text of the Chinese words are garbled .How to tackle the problem ?

create.php

<?php
// Include config file
require_once 'database.php';
header("Content-Type:text/html; charset=utf-8");
print_r($_POST);
// Define variables and initialize with empty values
$CName = $Address = $Amount = "";
$CName_err = $Address_err = $Amount_err = "";

// Processing form data when form is submitted
if($_SERVER["REQUEST_METHOD"] == "POST"){
    // Validate name
    $input_CName = trim($_POST["CName"]);
    if(empty($input_CName)){
        $CName_err = "Please enter a name.";
    } elseif(!filter_var(trim($_POST["CName"]), FILTER_VALIDATE_REGEXP, array("options"=>array("regexp"=>"/^[a-zA-Z'-.\s ]+$/")))){
        $CName_err = 'Please enter a valid name.';
    } else{
        $CName = $input_CName;
    }

    // Validate address
    $input_Address = trim($_POST["Address"]);
    if(empty($input_Address)){
        $Address_err = 'Please enter an address.';     
    } else{
        $Address = $input_Address;
    }

    // Validate Amount
    $input_Amount = trim($_POST["Amount"]);
    if(empty($input_Amount)){
        $Amount_err = "Please enter the amount.";     
    } elseif(!ctype_digit($input_Amount)){
        $Amount_err = 'Please enter a positive integer value.';
    } else{
        $Amount = $input_Amount;
    }

    // Check input errors before inserting in database
    if(empty($CName_err) && empty($Address_err) && empty($Amount_err)){
        // Prepare an insert statement
          $pdo = Database::connect();
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $sql = "INSERT INTO donation (CName, Address, Amount) VALUES (?, ?, ?)";

          $q = $pdo->prepare($sql);
          $q->execute(array($CName,$Address,$Amount));
            Database::disconnect();
            header("Location: index.php");
}}
?>

<!DOCTYPE html>
<!--<html lang="en">-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Create Record</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.css">
    <style type="text/css">
        .wrapper{
            width: 500px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <div class="page-header">
                        <h2>捐贈表格</h2>
                    </div>
                    <p>本人願意以信用卡捐款</p><br>
                    <p>I would like to make donation</p>
                    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
                        <div class="form-group <?php echo (!empty($CName_err)) ? 'has-error' : ''; ?>">
                            <label>Name</label>
                            <input type="text" name="CName" class="form-control" value="<?php echo $CName; ?>">
                            <span class="help-block"><?php echo $CName_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($Address_err)) ? 'has-error' : ''; ?>">
                            <label>Address</label>
                            <textarea name="Address" class="form-control"><?php echo $Address; ?></textarea>
                            <span class="help-block"><?php echo $Address_err;?></span>
                        </div>
                        <div class="form-group <?php echo (!empty($Amount_err)) ? 'has-error' : ''; ?>">
                            <label>Amount</label>
                            <input type="text" name="Amount" class="form-control" value="<?php echo $Amount; ?>">
                            <span class="help-block"><?php echo $Amount_err;?></span>
                        </div>
                        <input type="submit" class="btn btn-primary" value="Submit">
                        <a href="index.php" class="btn btn-default">Cancel</a>
                    </form>

                        <p>多謝您的支持</p><br>
                    <p>Thank you for your support</p>
                </div>
            </div>        
        </div>
    </div>
</body>
</html>

Update

garbled page : enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求lingo代码和思路
    • ¥15 公交车和无人机协同运输
    • ¥15 stm32代码移植没反应
    • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
    • ¥100 连续两帧图像高速减法
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
    • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)