doushichun9409 2016-03-11 21:07
浏览 158
已采纳

SQL语法错误和组合字符串错误

Below is a segment of code (note not complete code) that receives a json object parses some info to an array and the arrays in the json object into a string by changing the array to string via implode and adding it to the pervious string.

There seems to be two problems occurring:

1) it says Array to string conversion in /posi_rest_service.php on line 36

 $brontoJSONObject = $_POST['json'];
 $lineItems = ""; 
                $jsonIterator = new RecursiveIteratorIterator(
                new RecursiveArrayIterator(json_decode($brontoJSONObject, TRUE)),
                RecursiveIteratorIterator::SELF_FIRST);
                foreach ($jsonIterator as $key => $val) {
                    if(is_array($val)) {
                            $lineItems .=  '(*)' . (implode("|", $val)); //this is 36!!!!!!!
                        } else {
                            array_push($dataArray, $val);
                            $aCount++;
                        }
                    }
                $result = $conn->prepare("SELECT COUNT(*) FROM bronto_carts WHERE emailAddress = :emailAddress"); 
                $result->bindParam(':emailAddress', $dataArray[8]);
                $result->execute(); 
                $number_of_rows = $result->fetchColumn(); 
                if($number_of_rows > 0) {
                    $tmps = $conn->prepare("DELETE FROM bronto_carts where emailAddress = :emailAddress");
                    $tmps->bindParam(':emailAddress', $dataArray[8]);
                    $tmps->execute();
                }

EDIT new errors: Notice: Array to string conversion in /posi_rest_service.php on line 36

Strict Standards: Only variables should be passed by reference in /posi_rest_service.php on line 54

  • 写回答

1条回答

  • douxuanma4357 2016-03-11 21:34
    关注

    Try ignore it by use @. You can also try print_r( $val,true) instead of implode.

    $brontoJSONObject = $_POST['json'];
    $lineItems = ""; 
                $jsonIterator = new RecursiveIteratorIterator(
                new RecursiveArrayIterator(json_decode($brontoJSONObject, TRUE)),
                RecursiveIteratorIterator::SELF_FIRST);
                foreach ($jsonIterator as $key => $val) {
                    if(is_array($val)) {
                            $lineItems .=  '(*)' . (@implode("|", $val)); //this is 36!!!!!!!
                        } else {
                            array_push($dataArray, $val);
                            $aCount++;
                        }
                    }
                $result = $conn->prepare("SELECT COUNT(*) FROM bronto_carts WHERE emailAddress = :emailAddress"); 
                $result->bindParam(':emailAddress', $dataArray[8]);
                $result->execute(); 
                $number_of_rows = $result->fetchColumn(); 
                if($number_of_rows > 0) {
                    $tmps = $conn->prepare("DELETE FROM bronto_carts where emailAddress = :emailAddress");
                    $tmps->bindParam(':emailAddress', $dataArray[8]);
                    $tmps->execute();
                }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题