update items

This commit is contained in:
Page Asgardius 2022-10-01 09:13:04 -07:00
parent c0cfbd7df8
commit f702c4c508
3 changed files with 39 additions and 22 deletions

View file

@ -83,18 +83,21 @@ class Users{
$stmt = $this->conn->prepare(" $stmt = $this->conn->prepare("
UPDATE ".$this->itemsTable." UPDATE ".$this->itemsTable."
SET name= ?, description = ?, price = ?, category_id = ?, created = ? SET firstname= ?, lastname = ?, email = ?, password = ?, country = ?, birthdate = ?, permission = ?
WHERE id = ?"); WHERE id = ?");
$this->id = htmlspecialchars(strip_tags($this->id)); $this->id = htmlspecialchars(strip_tags($this->id));
$this->name = htmlspecialchars(strip_tags($this->name)); $this->firstname = htmlspecialchars(strip_tags($this->firstname));
$this->description = htmlspecialchars(strip_tags($this->description)); $this->lastname = htmlspecialchars(strip_tags($this->lastname));
$this->price = htmlspecialchars(strip_tags($this->price)); $this->email = htmlspecialchars(strip_tags($this->email));
$this->category_id = htmlspecialchars(strip_tags($this->category_id)); $this->password = htmlspecialchars(strip_tags($this->password));
$this->created = htmlspecialchars(strip_tags($this->created)); $this->country = htmlspecialchars(strip_tags($this->country));
$this->birthdate = htmlspecialchars(strip_tags($this->birthdate));
$stmt->bind_param("ssiisi", $this->name, $this->description, $this->price, $this->category_id, $this->created, $this->id); $this->permission = htmlspecialchars(strip_tags($this->permission));
$stmt->bind_param("ssssssss", $this->firstname, $this->lastname, $this->email, $this->password, $this->country, $this->birthdate, $this->permission, $this->id);
if($stmt->execute()){ if($stmt->execute()){
return true; return true;
} }

10
docs/update-example.txt Normal file
View file

@ -0,0 +1,10 @@
{
"id": "hackergirl",
"firstname": "Emily",
"lastname":"Asgardius",
"email":"hackergirl@asgardius.company",
"password": "test",
"country":"asteroid",
"birthdate": "1994-02-19",
"permission": "admin"
}

View file

@ -6,25 +6,29 @@ header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"); header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
include_once '../config/Database.php'; include_once '../config/Database.php';
include_once '../class/Items.php'; include_once '../class/Users.php';
$database = new Database(); $database = new Database();
$db = $database->getConnection(); $db = $database->getConnection();
$items = new Items($db); $items = new Users($db);
$data = json_decode(file_get_contents("php://input")); $data = json_decode(file_get_contents("php://input"));
if(!empty($data->id) && !empty($data->name) && if(!empty($data->id) && !empty($data->firstname) &&
!empty($data->description) && !empty($data->price) && !empty($data->lastname) && !empty($data->email) &&
!empty($data->category_id)){ !empty($data->password) && !empty($data->country) &&
!empty($data->birthdate) &&
$items->id = $data->id; !empty($data->permission)){
$items->name = $data->name;
$items->description = $data->description; $items->id = $data->id;
$items->price = $data->price; $items->firstname = $data->firstname;
$items->category_id = $data->category_id; $items->lastname = $data->lastname;
$items->created = date('Y-m-d H:i:s'); $items->email = $data->email;
$items->password = $data->password;
$items->country = $data->country;
$items->birthdate = $data->birthdate;
$items->permission = $data->permission;
if($items->update()){ if($items->update()){