Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/ovning9/1/
laggatill.php
skapatabell.php
skriverut.php
tabort.php
uppdatera.php
tabort.php
74 lines ASCII Windows (CRLF)
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Delete</title>
</head>
<body>
<?php
include ('../dbconnection.php');
$message = null;
$idnummer = null;
if (isset($_POST['idnummer']) && !empty($_POST['idnummer'])) {
$idnummer = $_POST['idnummer'];
try {
# prepare
$sql = "DELETE FROM kompisar WHERE idnummer=?";
$stmt = $dbconn->prepare($sql);
# the data we want to insert
$data = array($idnummer);
# execute width array-parameter
$stmt->execute($data);
$message .= "<br />Record deleted successfully.<br />";
}
catch(PDOException $e)
{
$message .= $sql . "<br>" . $e->getMessage();
}
} else {
$message .= "<br />";
}
echo $message;
// Ouput table with all posts
/*** The SQL SELECT statement ***/
$sql = "SELECT * FROM kompisar";
$stmt = $dbconn->prepare($sql);
// fetch width column names, create a table
$data = array();
$stmt->execute($data);
$output = "<table><caption>En ostylad tabell!</caption>";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$idnummerx = htmlentities($res['idnummer']);
$first = htmlentities($res['firstname']);
$last = htmlentities($res['lastname']);
$num = htmlentities($res['mobil']);
$email = htmlentities($res['email']);
$output .= "<tr>".
"<td>$idnummerx</td>".
"<td>$first</td>".
"<td>$last</td>".
"<td>$num</td>".
"<td>$email</td>".
"<td><form method='post' action=''>".
"<input type='hidden' name='idnummer' value='$idnummerx'>".
"<button type='submit'>Ta bort</button></form></td>".
"</tr>";
}
$output .= "</table>";
echo "$output";
$dbconn = null;
?>
<a href="../ovn_sql1.php">Tillbaks till meny</a>
</body>
</html>