无法将 PHP 和 MySQL 中的阿拉伯字母添加到我的数据库中的一个 table

Can't add Arabic letters in PHP and MySQL into one table of my database

我有这个 HTML 表单,可以将数据发送到 php 文件中:

 <table class="table table-striped" align="center" dir="rtl" style="width:auto" border="1">
    <thead align="center">
      <tr>
      <th colspan="11" style="text-align:center">المبيعات في: <?php echo $date_select ?></th>
      </tr>
      <tr>
      <th align="center">الاسم</th>
        <th align="center" style="text-align:center">النوع</th>
        <th align="center" style="text-align:center">الماركة</th>
        <th align="center" style="text-align:center">السعر</th>
        <th align="center" style="text-align:center">الدفعة</th>
        <th align="center" style="text-align:center">رقم الفاتورة</th>
        <th align="center" style="text-align:center">الكمية</th>
        <th align="center" style="text-align:center">تقسيط</th>
        <th align="center" style="text-align:center">كفالة</th>
        <th align="center" style="text-align:center">التاريخ</th>
        <th align="center" style="text-align:center">الوقت</th>
      </tr>
    </thead>

    <?php $sum = 0; foreach($result as $row){ $sum = $sum + $row['first_pay']; ?>
    <tbody>

    <tr>
    <td align="center" id="client_name"><?php echo $row['client_name'] ?></td>
    <td align="center" id="st"><?php echo $row['sale_type'] ?></td>
    <td align="center" id="sd"><?php echo $row['sale_detail'] ?></td>
    <td align="center" id="pr" name="pr"><?php echo $row['price'] ?></td>
    <td align="center"></td>
    <td align="center"><?php echo $row['facture_number'] ?></td>
    <td align="center"><?php echo $row['quantity'] ?></td>
    <td align="center" id="installment"><?php if($row['installment']=="yes"){ echo "نعم";} else { echo "لا";} ?></td>
    <td align="center"><?php if($row['warranty']=="yes"){ echo "نعم";} else { echo "لا";} ?></td>
    <td align="center" id="date_now"><?php echo $row['date_now'] ?></td>
    <td align="center" id="time_now"><?php echo $row['time_now'] ?></td>
    <td align="center"><form action='delete_with_debts.php' method="post">
    <input type="hidden" name="rowid" value="<?php echo $row['id'] ?>" />
    <input type="hidden" name="rowname" value="<?php echo $row['client_name'] ?>" />
    <input type="hidden" name="rowinstall" value="<?php echo $row['installment'] ?>" />
    <input type="hidden" name="rowdate" value="<?php echo $row['date_now'] ?>" />
    <input type="hidden" name="rowtime" value="<?php echo $row['time_now'] ?>" />
    <input type="hidden" name="sd" value="<?php echo $row['sale_detail'] ?>" />
    <input type="hidden" name="st" value="<?php echo $row['sale_type'] ?>" />
    <input type="hidden" name="qu" value="<?php echo $row['quantity'] ?>" />
    <input type="hidden" name="pr" value="<?php echo $row['price'] ?>" />
    <div id="printOption"><button type="submit" class="btn btn-danger btn-block btn-sm" id="delete_row" name="delete_row" onClick="return confirm('هل أنت متأكد؟ يرجى تعديل صفحة المشتريات بعد الغاء أحد المبيعات')">
  <span class="glyphicon glyphicon-repeat"></span> مرتجع
</button></div>
    </form></td>
    </tr>

这里是 php 文件:

<?php
require_once('../include/global.php');
If(isset($_POST['delete_row']))
{
    try
    {
        $id = $_POST['rowid'];
        $install = $_POST['rowinstall'];
        $date_now = $_POST['rowdate'];
        $time_now = $_POST['rowtime'];
        $client_name = $_POST['rowname'];
        $sd = $_POST['sd'];
        $st = $_POST['st'];
        $qu = $_POST['qu'];
        $pr = $_POST['pr'];
        if($install == "yes")
        {
            $sql = "SELECT * FROM client_debts WHERE date_now = :dtn AND time_now = :tmn";
            $sqlStmt = $conn->prepare($sql);
            $sqlStmt->bindValue(":dtn", $date_now);
            $sqlStmt->bindValue(":tmn", $time_now);
            $execute2 = $sqlStmt->execute();
            $fetchAll = $sqlStmt->fetchAll();
            foreach($fetchAll as $row)
            {
                $selectRow = "SELECT sum(payment) AS 'payment' FROM client_details WHERE client_id = :cid GROUP BY client_id";
                $selectRowStmt = $conn->prepare($selectRow);
                $selectRowStmt->bindValue(":cid", $row['id']);
                $execute3 = $selectRowStmt->execute();
                $res = $selectRowStmt->fetchColumn();
            }

            $sql2 = "DELETE FROM client_debts WHERE client_name = :client_name AND date_now = :date_now AND time_now = :time_now";
            $stmt2 = $conn->prepare($sql2);
            $stmt2->bindValue(':client_name', $client_name);
            $stmt2->bindValue(':date_now', $date_now);
            $stmt2->bindValue(':time_now', $time_now);
            $exec2 = $stmt2->execute();

            $rft = "From Customer";

            $ins = "INSERT INTO refund(item_name, refund_type, date_now, price)
                    VALUES(:item_name, :refund_type, :date_now, :price)";
            $insStmt = $conn->prepare($ins);
            $insStmt->bindValue(':item_name', $sd);
            $insStmt->bindValue(':refund_type', $rft);
            $insStmt->bindValue(':date_now', $date_now);
            $insStmt->bindValue(':price', $pr);
            $exec = $insStmt->execute();

            header("Location: purchases.php?type=".$st."&details=".$sd."&quantity=".$qu."&price=".$pr);
        }
        if($install == "no")
        {
            $rft = "From Customer";

            $ins = "INSERT INTO refund(item_name, refund_type, date_now, price)
                    VALUES(:item_name, :refund_type, :date_now, :price)";
            $insStmt = $conn->prepare($ins);
            $insStmt->bindValue(':item_name', $sd);
            $insStmt->bindValue(':refund_type', $rft);
            $insStmt->bindValue(':date_now', $date_now);
            $insStmt->bindValue(':price', $pr);
            $exec = $insStmt->execute();

            header("Location: purchases.php?type=".$st."&details=".$sd."&quantity=".$qu."&price=".$pr);
        }

    }
    catch(PDOException $e)
    {
        echo $e->getMessage();
    }
}
?>

在我的 html 页面顶部,我有这一行:

    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta HTTP-EQUIV="Pragma" content="no-cache">
    <meta HTTP-EQUIV="Expires" content="-1">

我的数据库设置为 utf8mb4 因为我需要使用阿拉伯字母,当我点击 delete_row 按钮时,我需要将删除的行插入不同的 table (出于会计目的)。

添加到 table 中的行是这样的 ????? ??:

我不明白为什么。

对于数据库尝试使用 utf8_general_ci 而不是 utf8mb4 。

通过 phpmyadmin 在您的数据库中更改下面的 table_name 和 运行 查询。

ALTER TABLE `table_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;