-
Notifications
You must be signed in to change notification settings - Fork 0
/
proj.php
94 lines (69 loc) · 2.95 KB
/
proj.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
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();
?>
<?php
$username = "root";
$password = "";
$host = "localhost";
$database = "LuanTech";
$conn = new mysqli($host,$username,$password,$database);
//if($conn->connect_error)
// die("Connection failed: " . $conn->connect_error);
function validate($input){
$input= strip_tags($input);
$input = trim($input);
$input = stripslashes($input);
$input = htmlspecialchars($input);
return $input;
}
$_SESSION['temp']=0;
if($conn){
if ( isset($_POST['user_id'])
&& isset($_POST['email']) && isset($_POST['password']) && isset($_POST['submit'])) {
$mail = validate($_POST['email']);
$user_id = validate($_POST['user_id']);
$password = validate($_POST['password']);
$_SESSION['email']=$mail;
$_SESSION['user_id']=$user_id;
$result = $conn->query("SELECT * FROM users WHERE EMAIL='$mail' OR USERNAME='$user_id'");
$row=$result->fetch_assoc();
$_SESSION['count']=$row['COUNT'];
if ($result->num_rows != 0) {
$_SESSION['temp'] = 1;
header("Location: login2.php?error=member already exist");
exit();
}else{
$insert = $conn->query("INSERT INTO users(USERNAME, EMAIL, PASSWORD)
VALUES ('$user_id','$mail','$password')");
if($insert){
$result = $conn->query("SELECT * FROM users WHERE EMAIL='$mail' AND PASSWORD='$password' AND USERNAME='$user_id'");
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
if ($row['USERNAME'] == $user_id) {
echo "Logged in!";
$_SESSION['USERNAME'] = $row['USERNAME'];
header("Location: home.html");
exit();
}
else{
echo "registeration failed";
}
}
}else{
header("Location: login.html"); //kant regestration:
echo("registration error");
}
}
}
else{
header("Location: login.html"); //kant regestration:
echo("registration error");
exit();
}
}
else{
// the differance between (die) and (echo) that echo will just write the nessage up but die will remove every thing then write the message in a wite website
die("Connection failed: " . $conn->connect_error);
//echo("not connected to the sever");
}
?>