Currently, I am working with angular CLI version 8.1.0 and have a user list displayed on a mat table. Upon clicking on a specific user, a new page opens up containing two buttons - "approve" and "reject". The issue I am facing is that when I click on "approve", the column should update from "pending" to "approve" for that particular user. However, instead of updating the column with the value "approve", it is being updated with an empty value. Could someone please assist me with this problem?
index.php
<?php
$conn=mysqli_connect("localhost","root","root","angdb");
$request=$_SERVER['REQUEST_METHOD'];
$data=array();
switch($request)
{
case 'GET':
response(getData());
break;
case 'PUT':
response(updateData());
default:
#code...
break;
}
function getData()
{
global $conn;
if(@$_GET['id'])
{
@$id=$_GET['id'];
$where="AND id=".$id;
}
else
{
$id=0;
$where="";
}
$query=mysqli_query($conn,"select * from vendor where status='pending' ".$where);
while($row=mysqli_fetch_assoc($query))
{
$data[]=array("id"=>$row['id'],"changeColumn"=>$row['changeColumn'],"type"=>$row['type'],"timestamp"=>$row['timestamp'],"status"=>$row['status'],"name"=>$row['name']);
}
return $data;
}
function updateData()
{
global $conn;
parse_str(file_get_contents('php://input'),$_PUT);
if(@$_GET['id'])
{
@$id=$_GET['id'];
$where="where id=".$id;
}
else
{
$id=0;
$where="";
}
$query=mysqli_query($conn,"update vendor set status='".$_PUT['status']."'".$where);
if($query==true)
{
$data[]=array("Message"=>"Updated");
}
else
{
$data[]=array("Message"=>"Not updated");
}
return $data;
}
function response($data)
{
echo json_encode($data);
}
?>
api.service.ts
updateById(id,payload)
{
let url = `http://localhost/angular_admin/php/index.php?id=${id}`
return this.httpClient.put(url, payload);
}
approval.component.ts
approve() {
this.apiService.updateById(this.id, {status:'approve'})
.subscribe((data:any)=> {
if (data.Message == "Updated") { // check if the result is sucess then navigat to
this.router.navigate(["/home/vendor-action"]);
}
});
}