gpt4 book ai didi

php - SQL语法错误&组合字符串错误

转载 作者:行者123 更新时间:2023-11-29 21:15:59 27 4
gpt4 key购买 nike

下面是一段代码(注意不是完整的代码),它接收一个 json 对象,将一些信息解析到一个数组中,然后通过 implode 将数组更改为字符串并将其添加到前面的字符串中,并将 json 对象中的数组转换为字符串字符串。

似乎出现了两个问题:

1) 它说 /posi_rest_service.php 第 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();
}

编辑新错误:注意:/posi_rest_service.php第36行中的数组到字符串转换

严格标准:仅应在/posi_rest_service.php 第 54 行中通过引用传递变量

最佳答案

尝试使用@忽略它。您也可以尝试 print_r( $val,true) 而不是 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();
}

关于php - SQL语法错误&组合字符串错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35949922/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com