[英]PHP passing array by POST and insert to oracle
我有很多復選框,檢查時將它們推送到數組並將值傳遞到下一頁。 下一頁需要提交選定的並在提交時我應該將一個數組傳遞到下一頁並插入到 Oracle DB。 在print_r
我可以看到我的數組的問題,但是在插入時,我收到了錯誤Notice: Array to string conversion in ...
。 這是我如何將數據傳遞到下一頁並接收它的代碼:
我做錯了什么? PS我寫的函數將解析數據並插入並需要傳遞數據作為這個例子(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)).'" />';
}
我使用了內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)).'" />'; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.