-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
94 lines (73 loc) · 2.96 KB
/
Copy pathprocess.php
File metadata and controls
94 lines (73 loc) · 2.96 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
<?php
session_start();
$customername="";
$customerPassword="";
$errors=array();
$host='localhost:3307';
$db=mysqli_connect("$host",'root','','pharmacy');
if (!$db) {
echo "<p>Could not connect to the server '" . $host . "'</p>\n";
echo mysql_error();
}else{
echo "<p>Successfully connected to the server '" . $host . "'</p>\n";
}
if(isset($_POST['customerSubmitButton'])){
$customername=mysqli_real_escape_string($db,$_POST['customer_name']);
$customerPassword=mysqli_real_escape_string($db,$_POST['password']);
if (empty($customername)) { array_push($errors, "name is required"); }
if (empty($customerPassword)) { array_push($errors, "Password is required"); }
$user_check_query = "SELECT * FROM customers WHERE customer_name='$customername' LIMIT 1";
$result = mysqli_query($db, $user_check_query);
$user = mysqli_fetch_assoc($result);
if ($user) {
if ($user['customer_name'] === $customername) {
array_push($errors, "User already exists");
}
}
if (count($errors) == 0) {
$query = "INSERT INTO customers (name, password)
VALUES('$customername', '$customerPassword')";
mysqli_query($db, $query);
$_SESSION['customer_name'] = $customername;
$_SESSION['success'] = "You are now logged in";
header('location: customerView.php');
}
}
if(isset($_POST['loginbutton'])){
$username=mysqli_real_escape_string($db,$_POST['name']);
$password=mysqli_real_escape_string($db,$_POST['password']);
$category=mysqli_real_escape_string($db,$_POST['category']);
if (empty($username)) {
array_push($errors, "Username is required");
}
if (empty($password)) {
array_push($errors, "Password is required");
}
if (empty($category)) {
array_push($errors, "Category is required");
}
if(count($errors)==0){
if($category=="customer"){
$query = "SELECT * FROM customers WHERE name='$username' AND password='$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$_SESSION['customer_name'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: customerView.php');
}else {
array_push($errors, "Wrong username/password combination");
}
}else if($category=="admin"){
$query = "SELECT * FROM admins WHERE name='$username' AND password='$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$_SESSION['admin_name'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: adminView.php');
}else {
array_push($errors, "Wrong username/password combination");
}
}
}
}
?>