面试宝典

Problem with: Fatal error: [] operator not supported for strings in Ask Question


I\'m getting information from database, saving it in array and echoing it in a form with loop structure and I\'m having problems when I try to save the modified information to database. I\'m getting this error: Fatal error: [] operator not supported for strings in....

You get this error when attempting to use the short array push syntax on a string.

For example, this

$foo = 'foo';
$foo[] = 'bar'; // ERROR!

I'd hazard a guess that one or more of your $name$date$text or $date2 variables has been initialised as a string.

Edit: Looking again at your question, it looks like you don't actually want to use them as arrays as you're treating them as strings further down.

If so, change your assignments to

$name = $row['name'];
$date = $row['date'];
$text = $row['text'];
$date2 = $row['date2'];