From 6a290235781cbca58dd1d102d030110b4eb0c6c9 Mon Sep 17 00:00:00 2001 From: Mateja Date: Fri, 2 Oct 2020 01:37:59 +0200 Subject: Prototype finished! --- test/edit.inc.php | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) (limited to 'test/edit.inc.php') diff --git a/test/edit.inc.php b/test/edit.inc.php index 3309a7b..a08a48a 100644 --- a/test/edit.inc.php +++ b/test/edit.inc.php @@ -1,7 +1,63 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $stmt = $conn->prepare("UPDATE tbl1 SET `name`=:name, `from`=:from, `to`=:to WHERE id=:id"); + $stmt->bindParam(':id', $_POST["id"]); + $stmt->bindParam(':name', $_POST["name"]); + $stmt->bindParam(':from', $_POST["from"]); + $stmt->bindParam(':to', $_POST["to"]); + $stmt->execute(); + + $data->action=$_POST["action"]; + echo json_encode($data); + } + catch (PDOException $e) { + echo $e->getMessage(); + } +} + +if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST["action"] == "restore") { + try { + $conn = new PDO("mysql:host=localhost;dbname=testdb", "testuser", "testpass"); + $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $stmt = $conn->prepare("SELECT * FROM tbl1 WHERE id=:id"); + $stmt->bindParam(':id', $_POST["id"]); + $stmt->execute(); + $row = $stmt->fetch(); + + $data->action=$_POST["action"]; + $data->id = $row["id"]; + $data->from = $row["from"]; + $data->to = $row["to"]; + $data->name = $row["name"]; + + echo json_encode($data); + } + catch (PDOException $e) { + echo $e->getMessage(); + } +} + +if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST["action"] == "delete") { + try { + $conn = new PDO("mysql:host=localhost;dbname=testdb", "testuser", "testpass"); + $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $stmt = $conn->prepare("DELETE FROM tbl1 WHERE id=:id"); + $stmt->bindParam(':id', $_POST["id"]); + $stmt->execute(); + + $data->action=$_POST["action"]; + echo json_encode($data); + } + catch (PDOException $e) { + echo $e->getMessage(); + } +} + +if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['email'])) { $email = clear_input($_POST['email']); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo "Email is not valid: " . $email . "
"; -- cgit v1.2.3