# Cannot convert value of type \`string\` to integer

**URL:** <https://discourse.cakephp.org/t/cannot-convert-value-of-type-string-to-integer/10503>\
**Category:** Need Help\
**Tags:** news, help\
**Created:** [July 4, 2022, 6:26pm UTC](https://discourse.cakephp.org/t/cannot-convert-value-of-type-string-to-integer/10503 "2022-07-04T18:26:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mestizo](https://avatars.discourse-cdn.com/v4/letter/m/c68b51/32.png) [@mestizo](https://discourse.cakephp.org/u/mestizo)\
**Post date:** [July 4, 2022, 6:26pm UTC](https://discourse.cakephp.org/t/cannot-convert-value-of-type-string-to-integer/10503/1 "2022-07-04T18:26:15Z")

</div>

good morning community.  
I am writing to you because I would like you to help me please with the following problem.  
I have a search engine in my code made in cakephp to perform searches by customer, source address and destination address, when I try to add the code to perform search by id it throws me the following error:  
Cannot convert value of type `string` to integer  
I share part of my code for a better understanding, I thank you in advance for your help

```auto
if ($this->request->is('post')){
            $q = $_REQUEST['q'];
            if ($q){
                $q = '%'.$q.'%'; 
                $query = $query->where(['OR' => [
                            'id LIKE' => $q, 
                            'Clients.name LIKE ' => $q,
                            'Deliveries.origin_address LIKE ' => $q, 
                            'Deliveries.destination_address LIKE ' => $q
                        ]]);
            }
        }

```

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [July 4, 2022, 6:51pm UTC](https://discourse.cakephp.org/t/cannot-convert-value-of-type-string-to-integer/10503/2 "2022-07-04T18:51:12Z")

</div>

First of all: You should NEVER have the need to access superglobals like `$_REQUEST` directly because you can easily use CakePHP to do much of the hard work for you.  
Try `$this->getRequest()->getQuery('q')` to access `GET` parameter or `$this->getRequest()->getData();` for e.g. POST data.

But anyway back to your problem:  
My guess would be that you try to search a `string` for integer columns, in your example the `id` column.

do you really want to implement a search for IDs with `'id LIKE' => '%'.$q.'%',` ?  
So e.g. if you you search `23` you get results with ids `23`, `234`, `123` etc.

I personally would rather put that `id` search in a separate input which can only be used as a number search instead of mixing up “fulltext” search with an “id search”

If you still want to do that you would have to parse the `$q` into a string because everything coming from GET parameters is a `string`, even if it is just `http://localhost?test=123`

So you have to do a

```auto
if(intval($q)){
    $test = intval($q);
}

```

before you do your query to change the type of your `$q` variable.
