0

I have many checkboxes and on check push them to an array and passing values to next page. Next page need for submitting selected and on submit I should pass an array to next page and do insert to Oracle DB. The problem that on print_r i can see my array, but on an insert, I got the error Notice: Array to string conversion in .... here is code how I pass data to next page and receive it:
What I do wrong? P.S. I wrote function that will parse data and insert and need to pass data as this example(1,2,1,1*5,5,6,2*7,3,4,5)
Here is my printed data 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)).'" />';
}
Orik0
  • 57
  • 7
  • in what line is the `Array to string conversion` notice occurred and what's the code of that line? – ariefbayu Dec 29 '17 at 10:39
  • maybe it's duplicated : https://stackoverflow.com/questions/20017409/how-to-solve-php-error-notice-array-to-string-conversion-in – Yassine CHABLI Dec 29 '17 at 10:40
  • it is not dublicate. Cause İ can print it to page, but can not insert it to DB – Orik0 Dec 29 '17 at 10:42
  • @ariefbayu on line ` $query = "insert into web.test values('".$arrayforfirst2 ."')` – Orik0 Dec 29 '17 at 10:57
  • That's your clue: the code expect `$arrayforfirst2` as `string`, instead of `array`. Why? because you want to concatenate it (by using the `.` (dot) symbol). – ariefbayu Dec 29 '17 at 11:07
  • @ariefbayu thanx fro reply. What can you advice to me? How can I convert it to string? – Orik0 Dec 29 '17 at 11:19

1 Answers1

0

I used implode method and converted it to string. Now it does not show an error) Inside my function i divide array with comma

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)).'" />';
}
Orik0
  • 57
  • 7