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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<?php
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST["action"] == "update") {
try {
$conn = new PDO("mysql:host=localhost;dbname=testdb", "testuser", "testpass");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("UPDATE tbl1 SET `name`=:name, `from`=:from, `to`=:to WHERE id=:id");
$stmt->bindParam(':id', $_POST["id"]);
$stmt->bindParam(':name', $_POST["name"]);
$stmt->bindParam(':from', $_POST["from"]);
$stmt->bindParam(':to', $_POST["to"]);
$stmt->execute();
$data->action=$_POST["action"];
echo json_encode($data);
}
catch (PDOException $e) {
echo $e->getMessage();
}
}
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST["action"] == "restore") {
try {
$conn = new PDO("mysql:host=localhost;dbname=testdb", "testuser", "testpass");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM tbl1 WHERE id=:id");
$stmt->bindParam(':id', $_POST["id"]);
$stmt->execute();
$row = $stmt->fetch();
$data->action=$_POST["action"];
$data->id = $row["id"];
$data->from = $row["from"];
$data->to = $row["to"];
$data->name = $row["name"];
echo json_encode($data);
}
catch (PDOException $e) {
echo $e->getMessage();
}
}
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST["action"] == "delete") {
try {
$conn = new PDO("mysql:host=localhost;dbname=testdb", "testuser", "testpass");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("DELETE FROM tbl1 WHERE id=:id");
$stmt->bindParam(':id', $_POST["id"]);
$stmt->execute();
$data->action=$_POST["action"];
echo json_encode($data);
}
catch (PDOException $e) {
echo $e->getMessage();
}
}
if($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['email'])) {
$email = clear_input($_POST['email']);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Email is not valid: " . $email . "<br>";
} else {
echo "Email is valid: " . $email . "<br>";
}
}
function clear_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
|