0

I've built a CMS in PHP and so far only ran it on my local server which is using XAMPP 3.2.2 at the moment. Everything worked fine until I uploaded it on my webserver (at Arvixe).

Here I get the error on the index page.

Parse error: syntax error, unexpected '[', expecting ')' in /home/tipsloqc/public_html/index.php on line 18

I've changed the PHP version of my Arvixe server in the public_html folder to the same version I have on my XAMPP server (5.4), but it was no use.

Any ideas why else the script may be failing?

<?php

require 'php/start.php';

$prevs = $DBH->query('SELECT * FROM prevs ORDER BY id DESC LIMIT 3')->fetchAll(PDO::FETCH_OBJ);

if (empty($_GET['cat'])) {
  $pages = $DBH->query('SELECT * FROM posts ORDER BY id DESC')->fetchAll(PDO::FETCH_OBJ);
}else{
  $cat = $_GET['cat'];

  $pages = $DBH->prepare("
        SELECT * FROM posts
        WHERE category = :cat
        ORDER BY id DESC
  ");

  $pages->execute(['cat' => $cat]);

  $pages = $pages->fetchAll(PDO::FETCH_OBJ);
}

$box = $DBH->query('SELECT * FROM box ORDER BY id DESC LIMIT 10')->fetchAll(PDO::FETCH_OBJ);


require VIEW_ROOT . '/home.php';
Panda
  • 6,955
  • 6
  • 40
  • 55
  • 5
    Short array syntax was implemented in PHP 5.4. If you get that error then your website is not running 5.4. – Sverri M. Olsen Apr 21 '16 at 22:01
  • Until you upgrade to 5.4, you can do it the *old-fashioned way*: `$pages->execute( array(':cat' => $cat) );` (don't forget you're binding :cat, so your array key must also be :cat) – mferly Apr 21 '16 at 22:06
  • You're absolutely right, however my webserver's PHP version is 5.6, which - if my calculations are correct - is higher than 5.3. – Dániel Emőd Kovács Apr 21 '16 at 22:30

0 Answers0