html - Warning</b>: Invalid argument supplied for foreach() in getting this error on parsing &,>,<, i.e htmlspecialchars to php script.How to avoid it? -


i trying parse data in handson table server side .i passing row row in json format , decoding array on server side. works fine when row doesn't have html specialchars gives above error when '&' ,'>','<' character present , data not updated row.here server side code. have data handsontable's row in $all_data variable. have php 5.1.6 , using pear extension json encode/decode.

here php code:

<?php include("/lan/fed/etpv/cgi-bin/testplans/php/my_functions.php"); ?> <?php $dbh=mysql_connect('a','b','c'); if(! $dbh ) {           die('could not connect: ' . mysql_error()); } $json = new services_json(services_json_loose_type); // json decode string array $database=mysql_select_db('testmohit'); $data_size = (int) $_server['content_length']; $testplan_name=$_post['testplan_name']; $product=$_post['product']; $release=$_post['release']; $pv_engg=$_post['pv_engg']; $pe_engg=$_post['pe_engg']; $rd_engg=$_post['rd_engg']; $tp_completion=$_post['tp_completion']; $at_completion=$_post['at_completion']; $logged_user=$_post['logged_user']; $plan_creator=$_post['plan_creator']; $headers=stripslashes($_post['headers']); $all_data = stripslashes($_post['all_data']); //# remove \ before " occur when parsed through ajax print"$all_data"; $all_data=htmlspecialchars($all_data); //print "$data_size"; $headers=$json->decode($headers); $all_data=$json->decode($all_data); for($j=0;$j<count($headers);$j++) {       $headers[$j]= str_replace(' ','_',strtolower("$headers[$j]")); } $date=date('y-m-d'); //print_r($all_data); $result = array(); foreach($all_data $key => $val){ //this done convert simple array associative array headers keys , all_data values values.     $temp = array();     foreach($val $k => $v){        $temp[$headers[$k]] = $v;     }     $fields=get_other_fields("$temp[testcase_path]");     if($temp[$headers[1]] == '') {     $temp[$headers[1]] = $fields['top_module_name'];     }     if($temp[$headers[2]] == '') {     $temp[$headers[2]] = $fields['customer_name'];     }     if($temp[$headers[3]] == '') {     $temp[$headers[3]] = $fields['flops'];     }     $result[] = $temp; }  //after data converted in required form            $query = "update testplans set percent_tpcompletion='$tp_completion',percent_atcompletion='$at_completion',tc_name='$temp[testcase_name]',cell_name='$temp[cell_name]',customer_name='$temp[customer]',flops='$temp[flops]',title='$temp[title]',status='$temp[status]',mfix_ccr='$temp[mfix_ccr]',test_scenerio='$temp[scenerio_brief_description]',expected_results='$temp[expected_results]',ccr_no='$temp[ccr_no]',ccr_status='$temp[status]',remarks='$temp[remarks]',edit_date='$date',edit_by='$logged_user' id='$temp[id]'";          # print "$query";          mysql_select_db('testmohit');           $enter=mysql_query($query,$dbh);           if(! $enter) {            die('could not enter data: ' . mysql_error());           } 

so saying when data in row($all_data) not have htmlspecialchars() query successful.else gives above error. how rectify .please suggest something.i tried using htmlspecialchars() function , didn't helped.

thanks


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -