Error with INT: A non well formed numeric value encountered in

Viewed 33

everyone. I am getting this error:

Notice: A non well formed numeric value encountered in C:\xampp\htdocs\backhoe\Controllers\Users.php on line 70

public function edit(int $id){ //This is my line 70
        $data = $this->model->editUser($id);
        echo json_encode($data, JSON_UNESCAPED_UNICODE);
        die();
    }

That function is in my controller Users. I call my editUser(id) function from my Model. This is my function in my model:

public function editUser(int $id){
        $sql = "SELECT * FROM offices WHERE offices.id = $id";
        $data = $this->select($sql);
        return $data;
    }

As you can see, I am sending an int called id and I am making my query. I call my select function from my Query.php:

public function select(string $sql){
        $this->sql = $sql;
        $res = $this->conn->prepare($this->sql);
        $res->execute();
        $data = $res->fetch(PDO::FETCH_ASSOC);
        return $data;
    }

And I have made thousands of checks and I am not misspelling something. I don't know what could be that non well formed numeric value... anyone knows about this error? I read someone who had an error like this but in his DB had VARCHAR instead of INT and I am calling an INT from my DB, I check that too.

The code where function edit() is called:

function editUser(id){
    document.getElementById("myModalTitle").innerHTML = "Actualizar usuario";
    document.getElementById("modalActionBtn").innerHTML = "Actualizar";
    const url = base_url + "Users/edit/"+id;
    const http = new XMLHttpRequest();
    http.open("GET",url,true);
    http.send();
    http.onreadystatechange = function(){
        if(this.readyState==4 && this.status == 200){
            console.log(this.responseText);
            const res = JSON.parse(this.responseText);
            document.getElementById("officeName").value = res.officeName;
            document.getElementById("manager").value = res.manager;
            document.getElementById("userName").value = res.userName;
            document.getElementById("roleId").value = res.roleId;
        }
    }
    $("#newUser").modal("show");
}

It is called as entering the url that contains the model and then the method + the id I need

0 Answers
Related