aboutsummaryrefslogtreecommitdiff
path: root/test/test2.php
blob: 8f2c697f9a5f1cb19814a530b04a59773ea3c09d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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>