diff options
author | Mateja <mail@matejamaric.com> | 2020-10-01 14:50:02 +0200 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2020-10-01 14:50:02 +0200 |
commit | 16939b4344b67ac8146015231af4d2fe691e90ce (patch) | |
tree | 50ba9f7093fd25d5d7aeee0ea5a240296fa68c98 /test/index.php | |
parent | 524fdc3a0ea3960823472e7e3f948b0cdd2003ef (diff) | |
download | old-php-yota-16939b4344b67ac8146015231af4d2fe691e90ce.tar.gz old-php-yota-16939b4344b67ac8146015231af4d2fe691e90ce.zip |
tiding up...
Diffstat (limited to 'test/index.php')
-rw-r--r-- | test/index.php | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/test/index.php b/test/index.php new file mode 100644 index 0000000..b0cb731 --- /dev/null +++ b/test/index.php @@ -0,0 +1,75 @@ +<?php +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 "<strong>You gay!</strong><br>"; +} +?> +<!DOCTYPE html> +<html lang="en"> +<head> +<meta charset="UTF-8"> +<title>Test table</title> +<style> + table { + border-collapse: collapse; + } + th, td { + border: 1px solid black; + padding: 0.2rem; + } +</style> +<script> +function subAction(action) { + var xhttp = new XMLHttpRequest(); + + xhttp.onreadystatechange = function() { + if(this.readyState == 4 && this.status == 200) { + console.log(this.responseText); + } + } + /* + xhttp.onload = function() { + console.log(this.responseText); + } + */ + xhttp.open("POST", "edit.inc.php", true); + xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhttp.send("action=" + action); +} +</script> +</head> +<body> +<form method="post"> +<label for="name">Name: </label> +<input type="text" name="name" id="name"> +<br> +<label for="date">Date: </label> +<input type="date" name="date" id="date"> +<br> +<label for="time">Time: </label> +<input type="time" name="time" id="time"> +<br> +<input type="submit" value="Submit"> +</form> +<?php +try { + $conn = new PDO("mysql:host=localhost;dbname=testdb", "testuser", "testpass"); + echo "<table>\n"; + echo "<thead><tr><th>ID</th><th>Name</th><th>Actions</th></tr></thead><tbody>\n"; + foreach ($conn->query("SELECT * FROM tbl1") as $row) { + echo "<tr><td>" . $row['id'] . "</td>"; + echo "<td contenteditable=\"true\">" . $row['name'] . "</td>"; + echo "<td>"; + echo "<button onclick=\"subAction('save')\">Save</button>"; + echo "<button onclick=\"subAction('cancel')\">Cancel</button>"; + echo "<button onclick=\"subAction('delete')\">Delete</button>"; + echo "</td></tr>\n"; + } + echo "</tbody></table>\n"; +} +catch (PDOException $e) { + echo $e->getMessage(); +} +?> +</body> +</html> |