From c9be3c9ed9bd1dcc497aff9de94a39e97721858e Mon Sep 17 00:00:00 2001 From: s439489 Date: Wed, 16 Feb 2022 23:26:38 +0100 Subject: [PATCH] initial commit --- action.php | 114 +++++++++++++++++++++++++++++ index.php | 211 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 325 insertions(+) create mode 100644 action.php create mode 100644 index.php diff --git a/action.php b/action.php new file mode 100644 index 0000000..57170bf --- /dev/null +++ b/action.php @@ -0,0 +1,114 @@ +action == 'fetchall'){ + $query = " + SELECT * FROM tbl_sample + ORDER BY id DESC + "; + $statement = $connect->prepare($query); + $statement->execute(); + while($row = $statement->fetch(PDO::FETCH_ASSOC)) + { + $data[] = $row; + } + echo json_encode($data); +} + +if($received_data->action == 'insert'){ + $data = array( + ':tytul' => $received_data->tytul, + ':autor' => $received_data->autor, + ':rok' => $received_data->rok + ); + + $query = " + INSERT INTO tbl_sample + (tytul, autor, rok) + VALUES (:tytul, :autor, :rok) + "; + + $statement = $connect->prepare($query); + + $statement->execute($data); + + $output = array( + 'message' => 'Data Inserted' + ); + + echo json_encode($output); +} + +if($received_data->action == 'fetchSingle'){ + $query = " + SELECT * FROM tbl_sample + WHERE id = '".$received_data->id."' + "; + + $statement = $connect->prepare($query); + + $statement->execute(); + + $result = $statement->fetchAll(); + + foreach($result as $row) + { + $data['id'] = $row['id']; + $data['tytul'] = $row['tytul']; + $data['autor'] = $row['autor']; + $data['rok'] = $row['rok']; + } + + echo json_encode($data); +} + +if($received_data->action == 'update'){ + $data = array( + ':tytul' => $received_data->tytul, + ':autor' => $received_data->autor, + ':rok' => $received_data->rok, + ':id' => $received_data->hiddenId + ); + + $query = " + UPDATE tbl_sample + SET tytul = :tytul, + autor = :autor, + rok = :rok + WHERE id = :id + "; + + $statement = $connect->prepare($query); + + $statement->execute($data); + + $output = array( + 'message' => 'Data Updated' + ); + + echo json_encode($output); +} + +if($received_data->action == 'delete'){ + $query = " + DELETE FROM tbl_sample + WHERE id = '".$received_data->id."' + "; + + $statement = $connect->prepare($query); + + $statement->execute(); + + $output = array( + 'message' => 'Data Deleted' + ); + + echo json_encode($output); +} + +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..0a01c37 --- /dev/null +++ b/index.php @@ -0,0 +1,211 @@ + + + + + + PHP Insert Update Delete with Vue.js + + + + + + +
+
+

Aplikacja do inwentaryzacji książek

+
+
+
+
+
+

Inwetaryzacja książek

+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + +
TytulAutorRokEditDelete
{{ row.tytul }}{{ row.autor }}{{ row.rok }}
+
+
+
+
+ + + +
+
+ + + +