diff options
author | Mateja <mail@matejamaric.com> | 2020-09-28 19:14:53 +0200 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2020-09-28 19:14:53 +0200 |
commit | 00fda2f0dfdaa1129949f0fa116cfaeff23ab486 (patch) | |
tree | 7ff6596f038c84771484da6c8150ce441aad89c6 /test/test2.php | |
download | old-php-yota-00fda2f0dfdaa1129949f0fa116cfaeff23ab486.tar.gz old-php-yota-00fda2f0dfdaa1129949f0fa116cfaeff23ab486.zip |
first commit
Diffstat (limited to 'test/test2.php')
-rw-r--r-- | test/test2.php | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/test2.php b/test/test2.php new file mode 100644 index 0000000..8f2c697 --- /dev/null +++ b/test/test2.php @@ -0,0 +1,56 @@ +<!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> +<?php +try { + $conn = new PDO("mysql:host=localhost;dbname=testdb", "testuser", "testpass"); + echo "<table>\n"; + echo "<tr><th>Name</th><th>Actions</th></tr>\n"; + foreach ($conn->query("SELECT * FROM tbl1") as $row) { + echo "<tr><td contenteditable=\"true\">" . $row['name'] . "</td>"; + echo "<td>"; + echo "<button onclick=\"subAction('save')\">Save</button>"; + echo "<button onclick=\"subAction('delete')\">Delete</button>"; + echo "</td></tr>\n"; + } + echo "</table>\n"; +} +catch (PDOException $e) { + echo $e->getMessage(); +} +?> +</body> +</html> |