Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/exercises/ovning9/2/
admin.php
deletetable.php
laggtill.php
skapatabell.php
skriverut.php
uppdatera.php
welcome.php
laggtill.php
84 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
78
79
80
81
82
83
84
<!-- createtable.php -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Create</title>
</head>
<body>
<?php
$message = null;
if (
isset($_POST['firstname']) && isset($_POST['lastname']) &&
!empty($_POST['firstname']) && !empty($_POST['lastname'])) {
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$anvandare = $_POST['anvandare'];
$passw = $_POST['passw'];
$typ = $_POST['typ'];
include ('../dbconnection.php');
try {
// sql to create table
$sql = "INSERT INTO anvandaretabell (firstname, lastname, anvandare, passw, typ, reg_date)
VALUES (?, ?, ?, ?, ?, now())";
$stmt = $dbconn->prepare($sql);
# the data we want to insert
$data = array($firstname, $lastname, $anvandare, $passw, $typ);
# execute width array-parameter
$stmt->execute($data);
echo "User created successfully";
// use exec() because no results are returned
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
}
//Rensa kopplingen till databasen
$dbconn = null;
?>
<form method="post" action="">
<table>
<tr>
<td>Förnamn*:</td>
<td><input type="text" name="firstname" size=40 maxlength=100 required>
</td>
</tr>
<tr>
<td>Efternamn*:</td>
<td><input type="text" name="lastname" size=40 maxlength=100 required></td>
</tr>
<tr>
<td>Anvandare*:</td>
<td><input type="text" name="anvandare" size=40 maxlength=100 required>
</td>
</tr>
<tr>
<td>Lösenord*:</td>
<td><input type="text" name="passw" size=20 maxlength=100 required>
</td>
</tr>
<tr>
<td>Typ:</td>
<td><select name="typ" required>
<option value="adminn">Admin</option>
<option value="usern">Användare</option>
</select></td>
</tr>
<tr>
<td>* = obligatoriskt</td>
<td><button type="submit">Lägg till</button></td>
</tr>
</table>
</form>
<a href="../ovn_sql2.php">Tillbaks till meny</a>
</body>
</html>