Я использую angular CLI 8.1.0. У меня есть список пользователей на коврике. Когда я нажимаю на любого пользователя, открывается новая страница. Эта страница содержит 2 кнопки «утвердить» и «отклонить», когда я нажимаю «утвердить», столбец должен быть обновлен с «в ожидании» до «одобрить» для данного пользователя. Но он обновляет столбец с пустым значением. Здесь я прилагаю свой код. Может кто-нибудь помочь, пожалуйста.
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);
}
official.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"]);
}
});
}