0

I am getting a error on my server on my MAMP server it worked but on my live server there is an error:

Parse error: syntax error, unexpected '[', expecting ')'

How to fix this? and what is wrong or why?

My code:

try {
    $sql = "INSERT INTO collection (name, numberO, city) VALUES (:name, :numberO, :city)";
    $statement = $db->prepare($sql);
    $sth = $statement->execute( ['name' => $name, 'numberO' => $number, 'city' => $city] );
} catch(PDOExepction $e) {
    echo "SORRY";
    exit;
}
1
  • 1
    You're on an older PHP version that doesn't support the [] array shortcut notation. Use ->execute(array(....)) instead. Commented Aug 21, 2014 at 16:59

2 Answers 2

3

Try this

$sth = $statement->execute(array(
    ':name' => $name, 
    ':numberO' => $number, 
    ':city' => $city
));

As of PHP 5.4 you can also use the short array syntax, which replaces array() with []. More about PHP array

Sign up to request clarification or add additional context in comments.

Comments

1

Check your server's php version.

You need PHP 5.4+ to use shorthand arrays

asp per PHP Doc:

As of PHP 5.4 you can also use the short array syntax, which replaces array() with [].

1) Update php version or
2) Change short hand array syntax

1 Comment

The server version is: 5.3.28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.