-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditjoke.php
29 lines (28 loc) · 879 Bytes
/
editjoke.php
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
<?php
include 'includes/database_connection.php';
try {
if (!isset($_POST['joketext'])) {
$sql = 'UPDATE joke SET joketext = :joketext WHERE id = :id';
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':joketext', $_POST['joketext']);
$stmt->bindValue(':id', $_POST['id']);
$stmt->execute();
header('Location: jokes.php');
}
else {
$sql = 'SELECT * FROM joke WHERE id = :id';
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':id', $_GET['id']);
$stmt->execute();
$joke = $stmt->fetch();
$title = 'Edit joke';
ob_start();
include 'templates/editjoke.html.php';
$output = ob_get_clean();
}
}catch (PDOException $e) {
$title = 'An error has occurred';
$output = 'Database error: ' . $e->getMessage();
}
include 'templates/layout.html.php';
?>