I coded an API in PHP-MySql. It works fine through PostMan. But when I want to modify a "partenaire" via my ANGULAR application, I have this error (see image).
Any idea please?
Here's the PHP :
// Update a partenaire in database
if ($api == 'PUT') {
parse_str(file_get_contents('php://input'), $post_input);
$g01 = $tuple->test_input($post_input['nomfranchise']);
$g02 = $tuple->test_input($post_input['sexegerant']);
$g03 = $tuple->test_input($post_input['nomgerant']);
$g04 = $tuple->test_input($post_input['mail']);
$g05 = $tuple->test_input($post_input['password']);
$g06 = $tuple->test_input($post_input['actif']);
$g07 = $tuple->test_input($post_input['grants']);
if ($id != null) {
if ($tuple->update($g01, $g02, $g03, $g04, $g05, $g06, $g07, $id)) {
echo $tuple->message('Partenaire modifié avec succès !',false);
} else {
echo $tuple->message('Erreur lors de la modification du partenaire !',true);
}
} else {
echo $tuple->message('Partenaire non trouvé !',true);
}
}
Then the Angular PartenaireComponent
onSubmitPartenaireForm(): void{
const partenaireId = this.partenaireForm.value.id;
let partenaire = this.partenaireForm.value;
if(!partenaireId || partenaireId && partenaireId == 0){
// CREATE ligne PARTENAIRE
delete partenaire.id;
this.apiService.createPartenaire(partenaire).subscribe((part: Partenaire)=>{
console.log("Partenaire crée, ", part);
});
} else {
// UPDATE
this.apiService.updatePartenaire(partenaireId, partenaire).subscribe((part: Partenaire)=>{
console.log("Partenaire mis à jour", part);
});
}
this.partenaireForm.reset();
this.titrePage = 'Enregistrer un nouveau partenaire';
}
And the ANGULAR ApiService
constructor(
private httpClient: HttpClient
) { }
createAuthorizationHeader(headers: HttpHeaders) {
headers.append('Authorization', 'Basic ');
}
updatePartenaire(id: number, partenaire: Partenaire): Observable<Partenaire>{
let headers = new HttpHeaders();
this.createAuthorizationHeader(headers);
return this.httpClient.put<Partenaire>(`${this.PHP_API_SERVER}partenaire.php/${id}`, partenaire, { headers : headers, responseType: "json" });
}
ANGULAR (front) https://github.com/fabienmacip/sallesport.git
PHP (APIs) https://github.com/fabienmacip/sallesport-api.git