0 Replies Latest reply on Oct 14, 2009 7:59 PM by tamyuho

    PHP and Mysql Update Chinese Problem


      I have problem on use HTTPService to send flex data with Chinese characters to PHP server page and update Mysql database to get ?? result. I tested it just send data to PHP and return data immediately from PHP to flex UI is correct. I think seems the problem narrow download to PHP and Mysql. Could anyone can help me advise a solution. Thanks you.


      ------------------------------------------------------------------------------------------ --------------------

      Below info is my Table Structure:


      CREATE TABLE chrm_leave_tran (
        roid int(11) NOT NULL AUTO_INCREMENT,
        userid varchar(30) NOT NULL,
        leave_type varchar(5) NOT NULL,
        start_date date NOT NULL,
        end_date date NOT NULL,
        remarks varchar(255) DEFAULT NULL,
        PRIMARY KEY (roid)


      Picture 1.png


      Notes: suppose the "leave_type" column display Chinese characters.



      PHP Server Page:




          $userid = $_POST['uid'];
          $leavetype = $_POST['ltype'];
          $sdate = $_POST['sdate'];
          $edate = $_POST['edate'];
          $ssection = $_POST['ssess'];
          $esection = $_POST['esess'];
          $remark = $_POST['rmk'];


           $server = 'localhost:8889';
           $mysql_user = 'root';
           $mysql_pwd = 'root';
           $db = 'chrms';


           $result = mysql_connect($server, $mysql_user, $mysql_pwd);


           if (!$result) {
               die ('Error connect mysql db'.mysql_error());


           if (!mysql_select_db($db)) {
               die('Select mysql db error'.mysql_error());


           $sql = mysql_query("SET NAMES = utf8");
           $sql = mysql_query("SET CHARACTER_SET_CLIENT = utf8");
           $sql = mysql_query("SET CHARACTER_SET_RESULTS = utf8");


           $sql = mysql_query("INSERT INTO chrm_leave_tran (userid,leave_type,start_date,end_date)
                                            VALUES('$userid', '$leavetype', '$sdate', '$edate')") or die (mysql_error());

           echo "Completed...".$leavetype;




      ActionScript 3


      protected function addLeaveRecord(uid:int):void
          var remoteData:HTTPService = new HTTPService();
          var param:Object = new Object();
          var tmpObj:Object = new Object();
          var df:DateFormatter = new DateFormatter();
          df.formatString = defaultDateFormat;
          remoteData.url = "http://localhost:8888/chrms/addleave.php";
          remoteData.contentType = "application/x-www-form-urlencoded";
          remoteData.method = "POST";
          remoteData.resultFormat = "text";
          remoteData.addEventListener(ResultEvent.RESULT, resultHandler);
          remoteData.addEventListener(FaultEvent.FAULT, faultHandler);
          for each (tmpObj in DGArraySource)
              param.uid = uid.toString();
              param.ltype = tmpObj.leaveType;

              param.sdate = df.format(tmpObj.startLeave);
              param.edate = df.format(tmpObj.endLeave);
              param.ssess = tmpObj.startSection;
              param.esess = tmpObj.endSection;
              param.rmk = tmpObj.description;


      private function resultHandler(event:ResultEvent):void


      private function faultHandler(event:FaultEvent):void


      ------------------------------------------------------------------------------------------ --------------------


      Thank you.