数组||非法抵消类型

时间:2017-01-14 18:10:02

标签: php mysql arrays offset

大家好,我有阵列问题。我想将数组保存到表中,但我收到了:

illegal offset type in C:\xampp\htdocs\app-mt\php\proses-edit-aplikasi.php on line 13

illegal offset type in C:\xampp\htdocs\app-mt\php\proses-edit-aplikasi.php on line 14

illegal offset type in C:\xampp\htdocs\app-mt\php\proses-edit-aplikasi.php on line 15

它显示给此代码

[1] => $value1,
[2] => $value2,
[3] => $value3

这是充满代码的

$value1 = $_POST['value1'];
$value2 = $_POST['value2'];
$value3 = $_POST['value3'];

$data_value = Array(
[1] => $value1,
[2] => $value2,
[3] => $value3
);
$array_value = serialize($data_value);

$query = "UPDATE maintenance
    SET pic                                 = '$pic',
        application_name                    = '$nama',
        maintenance_date                    = '$tanggal',
        entry_by                            = '$pictrans'

    WHERE maintenance_id = '$id'";
$query2 = "UPDATE INTO maintenance_detail
    SET value                               = '$array_value'

    WHERE maintenance_detail_id = '$id'";

$hasil = mysqli_query($db, $query);
$hasil2 = mysqli_query($db, $query2);

谢谢

1 个答案:

答案 0 :(得分:2)

问题是,您使用数组作为新数组的键。 [..]是定义新数组的简短方法。如果你想要数字键,只需摆脱周围的圆括号。

$data_value = Array(
    1 => $value1,
    2 => $value2,
    3 => $value3
);