PHP syntax error: Unexpected ']' [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm running PHP on a Windows 8.1 server with IIS. I have a PHP script, and have managed to turn displaying errors on. I found an error on this line.
$hr06status = mysqli_fetch_array(mysqli_query($connection, "SELECT status FROM hours WHERE hour = 6"))['status'];
The exact error is on line 14 Parse error: syntax error, unexpected '['

You trying to do array dereferencing which is only available in PHP 5.4 or later. You are probably running a version older than that so that line of code won't work.
The code in the comment above is the correct way to write it for your version of PHP.

Indexing on the return value of a function is something PHP added only recently. As Dave Chen says in the comment, you need an interim variable that you can then later index.

Related

What change from PHP version 5.2.3 to 5.3.27 would make same code give syntax error? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
What change from PHP version 5.2.3 to 5.3.27 would make same code give syntax error? I have a PHP code which while it's fine on 5.2.3 it doesn't work on 5.3.27 and give the following error in the last line of code:
( ! ) Parse error: syntax error, unexpected $end in index.php on line
832
It doesn't make any sense to me but I don't do PHP coding a lot of time. My question is if there's some syntax change or something like this which would make the syntax error.
Also, I'm using different servers Appserver and Vertrigo, if it's relevant.
EDIT:
In fact, the parser says that the error is on line 832 where the last line is 831. There's no extra } because if so it willn't run on the old version.
EDIT2:
Here's the last lines of code from actual program(it just doesn't work on recent PHP version):
<? } ?>
<?php
mysql_close($link);
?>
Maybe it's a configuration change and short_open_tag is differently configured.

php path error in imagejpeg() [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
when i use imagejpeg() it works fine in local while giving error on live
here is the warning message
Warning: imagejpeg() [function.imagejpeg]: Unable to open 'http://test.ourserv.com/Optfolder/cmp_dd5ac79bcf/20131027_185925.jpg' for writing: No such file or directory in /home3/test/public_html/server/Optfolder/image_re.php on line 36
i had same error with opendir() but when i write path like this it resolved but when i use even this kind of path instead of http it does not work with imagejpeg()
what is the path should i use,why path work locally fine and not on live server in php??
opendir('/home3/test/public_html/server/Optfolder/upload/upload');
use path like this
this will help you
$abs_dir=dirname(__FILE__);

ERROR 1030 (HY000): Got error -1 from storage engine [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
When I try to insert data into MySQL database I got this error:
Error Msg
#1030 - Got error -1 from storage engine
What could be the problem?
The first thing you do is check whether you are out of disk space.This error probably means you don't have enough memory for allocating to your table or database, or the specified memory settings for MySQL are too high for the configuration of your machine.
the following link may be useful to you http://wiki.jumpbox.com/doc/runtime/faq/mysql_maintenance

Wordpress: Fatal error: Call to undefined method Settings::printLinks() [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
This is the error I get when I load any of my sites but one:
Fatal error: Call to undefined method Settings::printLinks() in /home/admin/server/index.php on line 87
Call Stack: 0.0001 644544 1. {main}() /home/admin/server/index.php:0
The error showed about 2 hours ago caused by no obvious reasons... nothing has been moderated to cause it.
It happened yesterday to thousand (or more?) of wordpress users.
The mainly reasons are plugins, so disable them all.
If it still shows, then its probably caused by your theme
you can change it or upload it on another blog just to be sure
Problem for me was a popup plugin.

PDOStatement::fetch causing 500 Internal server error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm currently developing an auditing web app using PHP and MySQL. The app was developed locally using XAMPP without any issues. However after deploying it to my host's servers one of the php files that accesses the database using PDO started to generate a 500 internal server error. After some debugging the fetch() function was found to be the source.
// works
$sql="INSERT INTO subsection (section_id) VALUES (:section_id)";
$query=$db->prepare($sql);
$query->execute(array(':section_id'=>$section_id));
// doesn't work
$sql="SELECT audit_id FROM audit
WHERE audit_id < :audit_id
ORDER BY audit_id DESC LIMIT 1";
$query=$db->prepare($sql);
$query->execute(array(':audit_id'=>$audit_id));
$prevAuditId=$query->fetch()[0]; // <-- error generated here
phpinfo() reveals that the host's servers are running PHP version 5.33 and PDO support is enabled. So to summarise, the web app works locally on a XAMPP installation and when hosted PDO appears to function except for the fetch method().
Any clarification on this issue would be greatly appreciated.
The problem is that you're using PHP 5.3, but the array-dereferencing syntax you've used is only allowed from PHP 5.4 and up.
Here's your code:
$prevAuditId=$query->fetch()[0];
The problem is nothing to do with the PDO call, it's caused by the [0] at the end.
Getting an array element from a function call like this is called "dereferencing" the array. PHP 5.3 doesn't support this. If you need to stick with PHP 5.3, you'll have to split it out into two lines:
$auditRecord=$query->fetch();
$prevAuditId=$auditRecord[0];
Alternatively, you could upgrade your server to PHP 5.4 (or later), where your original syntax is valid.
Hope that helps.

Categories