diff options
author | Mateja <mail@matejamaric.com> | 2020-10-02 01:37:59 +0200 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2020-10-02 01:37:59 +0200 |
commit | 6a290235781cbca58dd1d102d030110b4eb0c6c9 (patch) | |
tree | eb4d1818ae6b322f6c69c2f3ead696532e125376 /test/edit.inc.php | |
parent | 110967fe02d337872508b2bba9cd48db138987ab (diff) | |
download | old-php-yota-6a290235781cbca58dd1d102d030110b4eb0c6c9.tar.gz old-php-yota-6a290235781cbca58dd1d102d030110b4eb0c6c9.zip |
Prototype finished!
Diffstat (limited to 'test/edit.inc.php')
-rw-r--r-- | test/edit.inc.php | 60 |
1 files changed, 58 insertions, 2 deletions
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 @@ <?php -echo $_POST['action']; -if($_SERVER["REQUEST_METHOD"] == "POST" && isset(_POST['email'])) { +if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST["action"] == "update") { + try { + $conn = new PDO("mysql:host=localhost;dbname=testdb", "testuser", "testpass"); + $conn->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 . "<br>"; |