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
- tinyint with display width 1 does not map to boolean, see: #526 — committed to mevdschee/php-crud-api by mevdschee 5 years ago
- tinyint with display width 1 does not map to boolean, see: #526 — committed to mevdschee/php-crud-api by mevdschee 5 years ago
- tinyint with display width 1 does not map to boolean, see: #526 — committed to mevdschee/php-crud-api by mevdschee 5 years ago
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 !
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
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:
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 :
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