Error: "Fatal Error: [] Operator Not Supported for Strings"
This error occurs when attempting to use the brackets ([]) operator on a string. In the provided code, you're attempting to access the elements of the $name, $date, $text, and $date2 arrays as strings. However, it appears that you haven't correctly initialized these variables as arrays.
Specifically, your code currently uses the following syntax:
$name = $row['name']; $date = $row['date']; $text = $row['text']; $date2 = $row['date2 '];
This syntax assigns the values from the database query to individual string variables. To create arrays, you can use the following syntax:
$name = [$row['name']]; $date = [$row['date']]; $text = [$row['text']]; $date2 = [$row['date2']];
By using the above syntax, you'll create arrays containing the database values.
Additionally, in your UPDATE query, you should separate the columns and values using commas, like this:
$wrotesql = "UPDATE service_report SET name='$name', date='$date', text='$text[$nro]', ser_date='$date2[$nro]' WHERE something = '$something'";
These changes should resolve the "Fatal Error: [] Operator Not Supported for Strings" error and allow you to use the array push syntax correctly.
The above is the detailed content of Why Does 'Fatal Error: [] Operator Not Supported for Strings' Occur When Accessing Database Values in PHP?. For more information, please follow other related articles on the PHP Chinese website!