-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignUp_auth.php
76 lines (63 loc) · 2.2 KB
/
SignUp_auth.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
<?php
include("connect.php");
$uname = $_POST['uname'];
$inst = $_POST['inst'];
$dept = $_POST['dept'];
$email = $_POST['email'];
$mobno = $_POST['mobno'];
$state = $_POST['state'];
$city = $_POST['city'];
$pass = $_POST['pass'];
$utype = $_POST['utype'];
if($utype == 'student') {
$uinfo = $_POST['sem'];
$udata = 'sem';
$table = 'students';
}
else {
$uinfo = $_POST['post'];
$udata = 'post';
$table = 'faculties';
}
$query = "select id from $table order by id";
$cmd = mysqli_query($con,$query);
while($row = mysqli_fetch_array($cmd)) {
$uid = $row['id'];
}
$uid++;
$image = $_FILES["uimg"];
// Check if file is uploaded successfully
// Read file contents
if ($image["error"] === UPLOAD_ERR_OK) {
$imageData = file_get_contents($_FILES["uimg"]["tmp_name"]);
$fileType = $_FILES["uimg"]["type"];
}
else {
$imageData = NULL;
$fileType = NULL;
}
// Password to be encrypted
$password = $_POST['pass'];
// Encrypt the password using password_hash() function
$hashed = password_hash($password, PASSWORD_DEFAULT);
// Store $hashedPassword in your database
echo "Encrypted Password: " . $hashedPassword;
// Prepare and bind the INSERT statement
$stmt = $con->prepare("INSERT INTO $table (pic,imgType,id,name,inst,dep,email,mob,state,city,pass,$udata)
VALUES (?,?,$uid,'$uname','$inst','$dept','$email',$mobno,'$state','$city','$hashed','$uinfo')");
$stmt->bind_param("ss", $imageData, $fileType);
// Execute the statement
if ($stmt->execute()) {
setcookie("userid",$uid,time() + (10 * 365 * 24 * 60 * 60));
setcookie("username",$uname,time() + (10 * 365 * 24 * 60 * 60));
setcookie("usertype",$utype,time() + (10 * 365 * 24 * 60 * 60));
header('location:index2.php');
} else {
$stmt->close();
$con->close();
header('location:SignUp.html');
}
// Close statement and database connection
$stmt->close();
$con->close();
?>