I am creating a REST API with PHP CodeIgniter paired with an MYSQL Database and an AngularJS Frontend. This is how my Database Table looks like: https://i.sstatic.net/piMZS.png
What Works
- I tested this API with a POST request from POSTMan like and it works perfectly.
account_name : "Test User 2"
display_name : "Test 2"
phone_no : 2832532
email : [email protected]
- This is the PHP response
Array
(
[account_name] => Test User 2
[display_name] => Test 2
[phone_no] => 2832532
[email] => [email protected]
)
What Doesn't work
- I am sending a request from Angular using HTTP Client. The Code:
onSubmit(){
let headers = new HttpHeaders();
headers.append("Content Type", "application/json");
headers.append("Accept", 'application/json');
let postData = {
account_name : "Test User 2",
display_name : "Test 2",
phone_no : "2832532",
email : "[email protected]"
}
this.http.post("http://localhost:8080/api/user-info/create-user", JSON.stringify(postData), {headers: headers})
.subscribe(data => {
console.log(data);
}, error => {
console.log(error);
console.log(JSON.stringify(postData))
})
}
}
- The issue is after JSON.stringify(postData) the postData becomes
{"account_name":"Test User 2",
"display_name":"Test 2",
"phone_no":"2832532",
"email":"[email protected]"}
- And I get an Internal Server Error 500
code: 500
message: "Column 'account_name' cannot be null"
title: "mysqli_sql_exception"
- And the PHP Response is
Array
(
[account_name] =>
[display_name] =>
[phone_no] =>
[email] =>
)
- The data is not receiving PHP whenever account_name becomes "account_name"
Any help with this will be highly appreciated. Thanks