Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/ovning9/3/
laggatill.php
skapatabell.php
visa.php
visaB.php
visaC.php
visaD.php
visaE.php
laggatill.php
77 lines UTF-8 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
75
76
77
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Namnlöst dokument</title>
</head>
<body>
<?php
$message = null;
if (
isset($_POST['regnr']) && isset($_POST['color']) && isset($_POST['garage']) &&
!empty($_POST['regnr']) && !empty($_POST['color']) && !empty($_POST['garage'])
) {
$regnr = $_POST['regnr'];
$color = $_POST['color'];
$garage = $_POST['garage'];
$owner = $_POST['owner'];
include('../dbconnection.php');
try {
# prepare
$sql = "INSERT INTO car (regnr, color, garage, owner)
VALUES (?, ?, ?, ?)";
$stmt = $dbconn->prepare($sql);
$data = array($regnr, $color, $garage, $owner);
$stmt->execute($data);
echo "New record created successfully";
} catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
$dbconn = null;
} else {
$message .= "<br />Du måste fylla i alla fälten!<br /><br />";
}
echo $message;
?>
<form method="post" action="">
<table>
<tr>
<td>Regrsteringsnummer*:</td>
<td><input type="text" name="regnr" size=40 maxlength=100>
</td>
</tr>
<tr>
<td>Färg*:</td>
<td><input type="text" name="color" size=40 maxlength=100></td>
</tr>
<tr>
<td>Garage*:</td>
<td><select name="garage" required>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select></td>
</tr>
<tr>
<td>Ägare*:</td>
<td><select name="owner" required>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select></td>
</tr>
<tr>
<td>* = obligatoriskt</td>
<td><button type="submit">Lägg till</button></td>
</tr>
</table>
</form>
<a href="../ovn_sql3.php">Tillbaks till meny</a>
</body>
</html>