Show sourcecode
The following files exists in this folder. Click to view.
webbserverprogrammering/exercises/mysqlintro/kryptering/
admin.php
dbconnection.php
deletepost.php
hemlig.php
index.php
insertpost.php
lås.php
selectposts.php
updatepost.php
insertpost.php
69 lines UTF-8 Windows (CRLF)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
<?php
session_start();
?>
<!-- insertpost.php -->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Insert</title>
</head>
<body>
<?php
include('lås.php');
$message = null;
if (isset($_POST['firstname']) && isset($_POST['lastname']) &&
!empty($_POST['firstname']) && !empty($_POST['lastname'])) {
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$password = $_POST['password'];
$admin = $_POST['admin'];
include ('dbconnection.php');
try {
# prepare
$password = password_hash($password, PASSWORD_DEFAULT);
$sql = "INSERT INTO anvandareKrypt (firstname, lastname, username, password, admin, reg_date)
VALUES (?, ?, ?, ?, ?, now())";
$stmt = $dbconn->prepare($sql);
# the data we want to insert
$data = array($firstname, $lastname, $username, $password, $admin);
# execute width array-parameter
$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 förnamn och efternamn!<br /><br />";
}
echo $message;
?>
<form method="post" action="">
<table>
<tr>
<td>Förnamn*:</td>
<td><input type="text" name="firstname" size=40 maxlength=100>
</td>
</tr>
<tr>
<td>Efternamn*:</td>
<td><input type="text" name="lastname" size=40 maxlength=100></td></tr>
<tr><td>Användare*:</td><td><input type="text" name="username" size=20 maxlength=30></td></tr>
<tr><td>Password*:</td><td><input type="text" name="password" size=20 maxlength=20></td></tr>
<tr><td>Admin*:</td><td><input type="text" name="admin"></td></tr>
<tr>
<td>* = obligatoriskt</td>
<td><button type="submit">Lägg till</button></td></tr>
</table>
</form>
<button onclick="window.location.href='admin.php'">Meny</button>
</body>
</html>