-
Notifications
You must be signed in to change notification settings - Fork 1
/
AccountHandler.php
69 lines (51 loc) · 1.89 KB
/
AccountHandler.php
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
<?php session_start();
if(isset($_POST["btnSubmit"])){
$email = $_POST["txtEmail"];
$password = $_POST["txtPassword"];
$admin1 = "[email protected]";
$admin2 = "[email protected]";
#localhost, root, pw, db name(that u created in phpMyadmin), port(check in wamp icon and mysql)
$con = mysqli_connect("localhost", "root", "", "novatech_database", "3306");
if(!$con){
die("Sorry, you can't connect to the database.");
}
$sql = "SELECT * FROM `user_tbl` WHERE `email` = '$email' AND `password` = '$password'";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result) > 0){
if($email===$admin1 || $email===$admin2){
$_SESSION["email"] = $email;
header("Location:admin.php");
}
else{
$_SESSION["email"] = $email;
header("Location:profile.php");
}
}
else{
echo "<script>
alert('Invalid login details');
window.location.href = 'login.php';
</script>";
}
}
// register handler
if(isset($_POST["btnRegister"])){
$name = $_POST["txtName"];
$email = $_POST["txtEmail"];
$password = $_POST["txtPassword"];
$contact = $_POST["txtContactNo"];
$address = $_POST["txtAddress"];
$imagePath = "img/mylogo3.png";
#localhost, root, pw, db name(that u created in phpMyadmin), port(check in wamp icon and mysql)
$con = mysqli_connect("localhost", "root", "", "novatech_database", "3306");
if(!$con){
die("Sorry, you can't connect to the database.");
}
$sql = "INSERT INTO `user_tbl` (`userID`, `email`, `name`, `contactNumber`, `address`, `password`, `imagePath`) VALUES (NULL, '$email', '$name', '$contact', '$address', '$password', '$imagePath')";
mysqli_query($con, $sql);
echo "<script>
alert('Success. login to your account');
window.location.href = 'login.php';
</script>";
}
?>