Home > Database > Mysql Tutorial > Why Does 'Fatal Error: [] Operator Not Supported for Strings' Occur When Accessing Database Values in PHP?

Why Does 'Fatal Error: [] Operator Not Supported for Strings' Occur When Accessing Database Values in PHP?

Susan Sarandon
Release: 2024-12-04 12:19:05
Original
1033 people have browsed it

Why Does

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 '];
Copy after login

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']];
Copy after login

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'";
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template