3

When I run the code below

  $data = array(
                'name' => $this->input->post('name'),
                'recipe' => $this->input->post('recipe'),
                'category_id' => $category_id,
                'recipe_elements' => $this->input->post('recipe_elements'),
                'country' => $this->input->post('country'),
                'video' => $this->input->post('video'),
                'img' => $img_name,
                'vote' => $this->input->post('oy')
            );

            $this->db->insert('recipes',$data);

I get this error

A PHP Error was encountered Severity: 4096
Message: Object of class stdClass could not be converted to string Filename: mysql/mysql_driver.php Line Number: 552 Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '

I already tried to change the input values but still getting the same error. Any help would be appreciated. How can I fix this?

1 Answer 1

4

You're trying to convert an object to a string.Please make sure $category_id and $img_name is not an object.

Take a look here this may help you. Object of class stdClass could not be converted to string

You can sse:$this->db->last_query(); which Returns the last query that was run (the query string, not the result). From where you can see easily your query string which also help you findout actual error.

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

1 Comment

Thank you for your reply. It seems I made a mistake on definening the $category_id variable.

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.