-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
65 lines (59 loc) · 1.67 KB
/
Copy pathindex.php
File metadata and controls
65 lines (59 loc) · 1.67 KB
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
<?PHP
session_start();
if ((isset($_SESSION['login']) && $_SESSION['login'] != '')) {
header ("Location: mylists.php");
}
$errorMessage = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
require '../../configure.php';
$uname = $_POST['username'];
$pword = $_POST['password'];
$database = "lists";
$db_found = new mysqli(DB_SERVER, DB_USER, DB_PASS, $database);
if ($db_found) {
$SQL = $db_found->prepare('SELECT * FROM login WHERE L1 = ?');
$SQL->bind_param('s', $uname);
$SQL->execute();
$result = $SQL->get_result();
if ($result->num_rows > 0) {
$errorMessage = "Username already taken";
}
else {
$phash = password_hash($pword, PASSWORD_DEFAULT);
$SQL = $db_found->prepare("INSERT INTO login (L1, L2) VALUES (?, ?)");
$SQL->bind_param('ss', $uname, $phash);
$SQL->execute();
header ("Location: login.php");
}
}
else {
$errorMessage = "Database Not Found";
}
}
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="liststyle.css">
<title>Welcome to Lists</title>
</head>
<body>
<div class="main-container">
<div class="listtitle">Welcome to Lists!</div>
<div class="list-container">
<form name ="form1" method ="post" action ="index.php">
<p>Register for an account:</p>
Username: <input type = 'text' name ='username' value="" >
<br>
<br>
Password: <input type = 'password' name ='password' value="" >
<br>
<br>
<input type = "submit" name = "Submit1" value = "Register">
</form>
<br>
Already have an account? <a href="login.php">Sign in</a>
</div>
<?PHP print $errorMessage;?>
</div>
</body>
</html>