1

I have this function on my code, and give me this error:

syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ')' on line 25

I cant find the error maybe you can see what I can't D:

public function InsertHero()
    {
        $this->load->view('Header');
        $this->load->view('HeroForm');
        $this->load->view('Footer');

        $data = array(
        'Name' -> $this -> input -> post('nick'), //this is the line 25
        'Power' -> $this -> input -> post('superpower'),
        'Phone' -> $this -> input -> post('phone'),
        'Email' -> $this -> input -> post('mail'),
        'Category' -> $this -> input -> post('category_id')
        );
        $this->model_heroes->insert($data);
        redirect(base_url());
    }
3
  • 2
    hash array syntax is $data = array('Name' => $this->input->post('nick')); Commented Sep 3, 2015 at 14:58
  • And here is your source to learn how to make arrays in php. php.net/manual/en/… Commented Sep 3, 2015 at 15:00
  • -_-'' thank you I forgot that ... Commented Sep 3, 2015 at 15:02

2 Answers 2

1

Simple error, you have used the operator for classes/objects (T_OBJECT_OPERATOR is ->) in your array declaration, when you should have used the T_DOUBLE_ARROW => operator.

Therefore your array should look like;

$data = array('Name' => $this->input->post('nick'));

For reference PHP operators

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

Comments

1

Per Rooney's comment, you do an array like this:

array( "foo" => "bar");

Not this:

array( "foo" -> "bar");

Comments

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.