0

I am trying to send query to mysql to insert some values into a table , this is not the first time I do this stuff and this is what making me getting crazy ! when I am printing the query it looks like this :

INSERT INTO hc_family_receive_relief (hc_family_id,hc_received_kind,hc_received_date,hc_received_month,hc_received_year) VALUES ('89','��� ��������','30','5','2014')

This is the first time I face this issue , what is the reason of it ? I even try to save the PHP file as UTF-8 , UTF-8 with out BOM , Arabic characters still not inserted to the table ! .

the following is the function that I used to create the query dinamicly from $_POST array :

function add_family_recieve_relief($array)
{
if(empty($array))
   return NULL;
$i = 0;
$titles = array();
$values = array();
$query = "INSERT INTO hc_family_receive_relief ";
foreach($array as $key => $value)
{
if($i == 0)
{
$titles[count($titles)] = "($key,";
$values[count($values)] = "('".$value."',";
}
if($i < count($array) - 1 && $i > 0)
{
$titles[count($titles)] = "$key,";
$values[count($values)] = "'".$value."',";
}
if($i == count($array) - 1)
{
$titles[count($titles)] = $key.") VALUES ";
$values[count($values)] = "'".$value."')";
}
$i++;
}

foreach($titles as $tvalue)
$query .= $tvalue;

foreach($values as $vvalue)
$query .= $vvalue;
echo $query;
$qresult = mysql_query($query);

if(!$qresult)
    return False;
else return True;
}

and this is the page that recive $_POST and pass it to function add_family_recieve_relief:

<?
require_once('../db.php');
require_once('familyReliefAPI.php');
if($_POST['addfamilyrelief'])
{
  if(empty($_POST['hc_family_id']) || !is_numeric($_POST['hc_family_id']))
      die('<center><h4><font color="red">خطأ في المعالجة , الرقم المميز للعائلة غير موجود !</font></h4></center>');
         $family_id = $_POST['hc_family_id'];
         array_pop($_POST);
  $addfrr = add_family_recieve_relief($_POST);
  if(!$addfrr)
       die('<center><h4><font color="red">مشكلة في الاضافة , الرجاء التأكد من المعلومات أو الاتصال</font></h4></center>');
    else {
         //print_r($_POST);
         }
}
?>

also I make SET NAMES utf-8 query in the connection page to fix the character issues , but still not work .. please HELP ME .. thanks

NOTE : The query is getting true and insert all the values in table except the arabic field it leaves it empty !

1 Answers1

0

Check the charset of the table which is present in the database

gvgvgvijayan
  • 1,851
  • 18
  • 34