1

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

  • 2
    perhaps the issue is in the code that calls the function `edit` ... not sure how showing a function that is called BY `edit` can help, since the issue is with the value passed TO `edit` rather than the value passed FROM `edit` – Jaromanda X Sep 23 '22 at 04:41
  • https://stackoverflow.com/questions/6136430/a-non-well-formed-numeric-value-encountered – Teemu Sep 23 '22 at 04:42
  • I put it at the end – Edgar Gerardo Sep 23 '22 at 08:27
  • If `$id` is a query parameter in the URL, it's safest to also parametrize the SQL query, otherwise it's vulnerable to SQL injection. What comes to the error, I suppose `$id` is a string, but `edit` method expects an integer. – Teemu Sep 23 '22 at 10:04
  • No.. That's what I explained. In my Database, id is an integer – Edgar Gerardo Sep 23 '22 at 15:12
  • @Anant-Alivetodie my problem is not with time and is not a data type problem. I can't find the error – Edgar Gerardo Sep 23 '22 at 18:04
  • Something is calling **editUser** with **id**, where is this code? Its telling you what is wrong. And my bet is that it is correct. I am voting to close the question. – Rohit Gupta Sep 24 '22 at 22:55
  • The first code is where editUser is called. I'm saving what it returns in $data which is in my model and that code is in the second code section I wrote here... – Edgar Gerardo Sep 25 '22 at 16:02
  • `function editUser(id){` needs to be `function editUser($id){`. isn't it? `$` sign missing around `id` – Alive to die - Anant Sep 26 '22 at 04:47
  • try this : `const url = base_url + "Users/edit/"+parseInt(id);` – Alive to die - Anant Sep 26 '22 at 04:52
  • http protocol transfers strings only, you've to explicitly convert the id to an integer. – Teemu Sep 26 '22 at 09:40

0 Answers0