我有很多复选框,并在检查时将它们推送到一个数组并将值传递给下一页。下一页需要提交选中和提交我应该将数组传递到下一页并插入Oracle DB。问题print_r
我可以看到我的数组,但在插入时,我得到了错误Notice: Array to string conversion in ...
。
这是代码如何将数据传递到下一页并接收它:
我做错了什么?
附:我编写的函数将解析数据并插入并需要传递数据,例如(1,2,1,1*5,5,6,2*7,3,4,5)
这是我打印的数据Array ( [0] => 6 [1] => 1 [2] => 1 [3] => 5* [4] => 10 [5] => 1 [6] => 1 [7] => 5* [8] => 14 [9] => 1 [10] => 1 [11] => 5* [12] => 18 [13] => 1 [14] => 1 [15] => 5* )
if(some condition) {
//here i check checkboxes, pshing values to array
} else if(isset($_POST["arrayforfirst"])){
$arrayforfirst = $_POST['arrayforfirst'];
$arrayforfirst2 = unserialize(base64_decode($arrayforfirst));
print_r($arrayforfirst2);
$query = "my insert query";
$stmt1 = oci_parse($my_connection, $query);
oci_execute($stmt1);
} else {
$newarray = array();
foreach($_POST['myarray'] as $id => $value) {
$pp = explode(",", $value);
array_push($newarray, $pp[2], $pp[3], $pp[4], $pp[1].'*');
}
echo '<input type="hidden" name = "arrayforfirst" value="'.base64_encode(serialize($newarray)).'" />';
}
答案 0 :(得分:0)
我使用了implode
方法并将其转换为字符串。现在它没有显示错误)在我的函数内部我用逗号分隔数组
if(some condition) {
//here i check checkboxes, pshing values to array
} else if(isset($_POST["arrayforfirst"])){
$arrayforfirst = $_POST['arrayforfirst'];
$arrayforfirst2 = unserialize(base64_decode($arrayforfirst));
$pp = implode(',',$arrayforfirst2);
print_r($arrayforfirst2);
$query = "my insert query";
$stmt1 = oci_parse($my_connection, $query);
oci_execute($stmt1);
} else {
$newarray = array();
foreach($_POST['myarray'] as $id => $value) {
$pp = explode(",", $value);
array_push($newarray, $pp[2], $pp[3], $pp[4], $pp[1].'*');
}
echo '<input type="hidden" name = "arrayforfirst" value="'.base64_encode(serialize($newarray)).'" />';
}
&#13;