diff options
author | Mateja <mail@matejamaric.com> | 2020-10-01 15:50:36 +0200 |
---|---|---|
committer | Mateja <mail@matejamaric.com> | 2020-10-01 15:50:36 +0200 |
commit | 83ee4c20beabfc33a0572a053404d6c34319ade9 (patch) | |
tree | b114e652a4ae4021f884f460583ca197ed423af2 /test/index.php | |
parent | 16939b4344b67ac8146015231af4d2fe691e90ce (diff) | |
download | old-php-yota-83ee4c20beabfc33a0572a053404d6c34319ade9.tar.gz old-php-yota-83ee4c20beabfc33a0572a053404d6c34319ade9.zip |
DateTime PHP to DB work
Diffstat (limited to 'test/index.php')
-rw-r--r-- | test/index.php | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/test/index.php b/test/index.php index b0cb731..3b1d7c0 100644 --- a/test/index.php +++ b/test/index.php @@ -1,7 +1,21 @@ <?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>"; + echo "<strong>Information submitted!</strong><br>"; + echo "<strong>Date: " . date('Y-m-d H:i:s') . "</strong><br>"; + 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(); + } + catch (PDOException $e) { + echo $e->getMessage(); + } } ?> <!DOCTYPE html> @@ -15,7 +29,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["name"]) && isset($_POS } th, td { border: 1px solid black; - padding: 0.2rem; + padding: 0.3rem; } </style> <script> @@ -53,11 +67,12 @@ function subAction(action) { </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"; + echo "<thead><tr><th>ID</th><th>From</th><th>To</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>" . $row['from'] . "</td>"; + echo "<td>" . $row['to'] . "</td>"; echo "<td contenteditable=\"true\">" . $row['name'] . "</td>"; echo "<td>"; echo "<button onclick=\"subAction('save')\">Save</button>"; |