1

I have this HTML form that sends data into a php file:

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

And here is the php file:

<?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();
    }
}
?>

At the top of my html page, I have this line:

    <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">

My Database is set to utf8mb4 because I need to work with Arabic letters and when I click on the delete_row button, I need to insert the row deleted into different table (for accounting purposes).

The added row into the table is like this ????? ??:

enter image description here

I can't figure it out why.

androidnation
  • 626
  • 1
  • 7
  • 19

2 Answers2

2

For database try use utf8_general_ci instead of utf8mb4 .

NormundsP
  • 445
  • 2
  • 7
  • 16
  • still the same issue – androidnation Mar 21 '16 at 14:49
  • And add this: $conn->exec("set names utf8"); – NormundsP Mar 21 '16 at 14:52
  • I have it in my connection file – androidnation Mar 21 '16 at 14:53
  • 1
    You hav tried this: http://stackoverflow.com/questions/6859018/save-data-in-arabic-in-mysql-database Quote: "To read ,write and sort Arabic text in mysql database using php correctly, make sure that: MySQL charset: UTF-8 Unicode (utf8) MySQL connection collation: utf8_general_ci your database and table collations are set to: utf8_general_ci or utf8_unicode_ci Then, add this code in your php script when you connect to db: mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8');" – NormundsP Mar 21 '16 at 15:08
1

Change table_name and Run below query in your database by phpmyadmin.

ALTER TABLE `table_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;     
Noman
  • 4,088
  • 1
  • 21
  • 36