-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview_verify.php
More file actions
120 lines (83 loc) · 3.32 KB
/
view_verify.php
File metadata and controls
120 lines (83 loc) · 3.32 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php ob_start(); session_start();
if (isset($_SESSION["codeC"]) && isset($_SESSION["userAdded"])) {
$correctCode = $_SESSION["codeC"];
$usernameVerified = $_SESSION["userAdded"];
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Verify</title>
<meta charset="UTF-8">
<script type="text/javascript">
function codeIsCorrect() {
document.getElementById("lblError").innerHTML = "Please enter a code.";//clear error labels
var userCode = document.getElementById("txtCode").value;
var correctCode = "<?php echo get_this_code($_SESSION["userAdded"]); ?>";//the right code
var usernameVerified = "<?php echo $_SESSION["userAdded"]; ?>";
if (userCode == ""){
//document.getElementById("lblError").innerHTML = "Wrong code. Try again.";
document.getElementById("lblError").innerHTML = "Please enter a code.";
//alert("Please enter a code.");
return false;
}
else if (userCode == correctCode) {
//update their verified status to true i.e "1"in db
return true;
}
else {
document.getElementById("lblError").innerHTML = "Wrong code. Try again.";
//alert("Try again.");
return false;
}
}
</script>
<link type="text/css" rel="stylesheet" href="style.css" />
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="inside">
<div class="inn">
<a href="index.php">Home</a>
<a href="">Back</a>
<form id="frmRegister" action="model_login_reg.php" method="post">
<div>
<h2>Verify Account</h2>
<label id="lblCode">Enter activation code:</label>
<input type="text" id="txtCode" name="code">
<input type="submit" value="Register" name="register" onclick="return codeIsCorrect();">
<label style="color:red;" id="lblError"></label>
<label id="lblCode"></label>
</div>
</form>
</div>
</div>
</body>
</html>
<?php
function db_connect(){
$dbname = "mdb_st8511x";
$host = "mysql.cms.gre.ac.uk";
$username = "st8511x";
$password = "tina2";
//$host = "localhost";
//$username = "root";
//$password = "";
//est. connection
$conn = mysqli_connect($host, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . $conn->connect_error);
}
//echo "Connected successfully";
return $conn;
}//db_connect
function get_this_code($username){
$conn = db_connect();
$username = mysqli_real_escape_string($conn,$username);
$sql = "SELECT code FROM user WHERE username = '".$username."'";
$result = mysqli_query($conn,$sql);
$value = mysqli_fetch_assoc($result);
return $value['code'];
}
?>