From 110967fe02d337872508b2bba9cd48db138987ab Mon Sep 17 00:00:00 2001 From: Mateja Date: Thu, 1 Oct 2020 22:39:38 +0200 Subject: Work on button and styling... --- test/index.php | 66 +++++++++++++++++++++++++++++++++------------------------ test/request.js | 38 +++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 28 deletions(-) create mode 100644 test/request.js (limited to 'test') diff --git a/test/index.php b/test/index.php index 3b1d7c0..fb6e942 100644 --- a/test/index.php +++ b/test/index.php @@ -1,15 +1,24 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + catch (PDOException $e) { + echo $e->getMessage(); + } if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["name"]) && isset($_POST["date"]) && isset($_POST["time"])) { # values will always be set, check if they are empty... echo "Information submitted!
"; echo "Date: " . date('Y-m-d H:i:s') . "
"; + echo "User date: " . $_POST["date"] . "
"; + echo "User time: " . $_POST["time"] . "
"; + //$toDT='2020-10-10 12:00:00'; + $toDT=$_POST["date"] . " " . $_POST["time"] . ":00"; + echo "$toDT
"; try { - $conn = new PDO("mysql:host=localhost;dbname=testdb", "testuser", "testpass"); - $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare("INSERT INTO tbl1 (`name`, `from`, `to`) VALUES (:name, :from, :to)"); $stmt->bindParam(':name', $_POST['name']); $stmt->bindParam(':from', date('Y-m-d H:i:s')); - $toDT='2020-10-10 12:00:00'; $stmt->bindParam(':to', $toDT); $stmt->execute(); } @@ -24,6 +33,9 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["name"]) && isset($_POS Test table - + .edit { + padding: 2px; + border-top: 1px solid #333; + border-left: 1px solid #333; + border-bottom: 1px solid #666; + border-right: 1px solid #666; + border-radius: 3px; + } + +

@@ -69,15 +78,15 @@ function subAction(action) { try { echo "\n"; echo "\n"; - foreach ($conn->query("SELECT * FROM tbl1") as $row) { + foreach ($conn->query("SELECT * FROM tbl1 ORDER BY `id` DESC") as $row) { echo ""; - echo ""; - echo ""; - echo ""; + echo ""; + echo ""; + echo ""; echo "\n"; } echo "
IDFromToNameActions
" . $row['id'] . "" . $row['from'] . "" . $row['to'] . "" . $row['name'] . "
" . $row['from'] . "
" . $row['to'] . "
" . $row['name'] . "
"; - echo ""; - echo ""; - echo ""; + echo ""; + echo ""; + echo ""; echo "
\n"; @@ -86,5 +95,6 @@ catch (PDOException $e) { echo $e->getMessage(); } ?> + diff --git a/test/request.js b/test/request.js new file mode 100644 index 0000000..bfcf592 --- /dev/null +++ b/test/request.js @@ -0,0 +1,38 @@ +function subAction(action, btn) { + trDom = btn.parentElement.parentElement; + trData = trDom.children; + + trId = trData[0].innerHTML; + trFrom = trData[1].innerHTML; + trTo = trData[2].innerHTML; + trName = trData[3].innerHTML; + + console.log(trId); + console.log(trFrom); + console.log(trTo); + console.log(trName); + + //for (var i = 0, len = trData.length - 1; i < len; i++) { + //console.log(i + ": " + trData[i].innerHTML); + //} + + if (action == 'delete') + if (confirm("Are you sure you want to delete this reservation?")) + trDom.remove(); + + // Send XHR + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState == 4 && this.status == 200) { + document.getElementById("notice").innerHTML = this.responseText; + } + } + xhttp.open("POST", "edit.inc.php", true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + data_str = "action=" + action + data_str += "&id=" + trId + data_str += "&from=" + trFrom + data_str += "&to=" + trTo + data_str += "&name=" + trName + xhttp.send(data_str); +} -- cgit v1.2.3