php-crud-api: Error 500 while doing a post request

Hello,

I have a problem while executing a POST request. Here is what my request looks like : const dette = {"id_user":233,"created_dt":"2019-04-09","amount":10,"commentaire":"test","paid":0,"modified_dt":"2019-04-09"}

 fetch('https://www.mydomain.com/api/api.php/records/v2_dettes', {
      method: 'POST',
      body: dette
    })
      .then(() => {})
      .catch(error => {
        console.log(error);
      });
  };

Here is my table : https://screenshots.firefox.com/DhddAg9g0i9gOZHL/phpmyadmin.ovh.net

And what the request respond to me : {"code":9999,"message":"Call to a member function execute() on boolean"}

GET,UPDATE and DELETE are working like a charm. But with the POST request, the api return me an internal error 500 but my record is present in the database ! Do you have any ideas why the api is raising me this error ?

Thanks in advance

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Hello,

Sorry I’m a little bit out of time atm. I will double check for invisible characters as soon as possible. Thanks for you help !

 1 row inserted.
Inserted row id: 469 (Query took 0.0004 seconds.)
INSERT INTO `v2_dettes` (`id_user`, `created_dt`, `modified_dt`, `amount`, `commentaire`, `paid`) VALUES (223, '2019-04-09', '2019-04-09', 10, 'test', 0) 

But remember that the POST to the api is working (the row is added to the db) but it’s just that the API raise me an error ! My app using the api is working, but I need to ignore the error given by the api.

Yes. I changed nothing excepts credentials and the middleware cors in the api.php

string(113) “INSERT INTO “v2_dettes” (“id_user”,“created_dt”,“modified_dt”,“amount”,“commentaire”,“paid”) VALUES (?,?,?,?,?,?)” array(3) { [0]=> string(5) “00000” [1]=> NULL [2]=> NULL } string(23) “SELECT LAST_INSERT_ID()” array(3) { [0]=> string(5) “00000” [1]=> NULL [2]=> NULL } {“code”:9999,“message”:“Call to a member function execute() on boolean”}

I don’t know why, but the response is not complete.

Response raw: string(113) "INSERT INTO "v2_dettes" ("id_user","created_dt","modified_dt"

Response header:

content-length →74 content-type →application/json date →Fri, 12 Apr 2019 09:09:35 GMT server →Apache x-exception-file →/home/odsladqg/www/api/api.php:2016 x-exception-message →Call to a member function errorInfo() on boolean x-iplb-instance →17329 x-powered-by →PHP/7.2

Maybe I can send you the url of my api by mail ?

Thanks for the follow up ! Indeed, your setup seems the same.

Here is the response header with the debug true :

HTTP/1.1 500 Internal Server Error Set-Cookie: 60gp=R4109521858; path=/; expires=Fri, 12-Apr-2019 09:26:46 GMT Date: Fri, 12 Apr 2019 08:19:28 GMT Server: Apache X-Powered-By: PHP/7.2 Content-Length: 72 X-Exception-Message: Call to a member function execute() on boolean X-Exception-File: /home/odsladqg/www/api/api.php:2015 Content-Type: application/json X-IPLB-Instance: 504

https://github.com/mevdschee/php-crud-api/blob/master/api.php#L2015

I tried through a browser and directly with curl. Same result.

I only have one in my db structure. If it’s a bugm I can’t help you on that because of my poor php skills.

First, thanks for you response

When using "paid’: false, i got : {"code":9999,"message":"SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'paid' at row 1"}

So 1/0 seems to be the right way to pass the value.

Hi, tinyint(1) is mapped with boolean for mysql If you change “paid”:0 to “paid”:false, it might work