Pullapooh
Pullapooh

Reputation: 161

Php bindParam error

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;
}

Upvotes: 0

Views: 125

Answers (2)

MH2K9
MH2K9

Reputation: 12039

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

Upvotes: 3

Awlad Liton
Awlad Liton

Reputation: 9351

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

Upvotes: 1

Related Questions