-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoEdit.php
66 lines (57 loc) · 2.12 KB
/
DoEdit.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
<?php
include("connect.php");
$id = $_POST['uid'];
$uname = $_POST['uname'];
$inst = $_POST['inst'];
$dept = $_POST['dept'];
$email = $_POST['email'];
$mobno = $_POST['mobno'];
$state = $_POST['state'];
$city = $_POST['city'];
$bio = $_POST['bio'];
$utype = $_POST['utype'];
//$pass = $_POST['pass'];
$password = $_POST['pass'];
// Encrypt the password using password_hash() function
$hashed = password_hash($password, PASSWORD_DEFAULT);
setcookie("username",$uname,time() + (10 * 365 * 24 * 60 * 60));
echo $utype;
if($utype == 'students') {
$uinfo = $_POST['sem'];
$udata = 'sem';
$table = 'students';
$location = "Students/S_edit.php?id=$id";
}
else {
$uinfo = $_POST['post'];
$udata = 'post';
$table = 'faculties';
$location = "Faculties/F_edit.php?id=$id";
}
$query = "select id from $table";
$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"];
}
// Prepare and bind the INSERT statement
if($image['name'] == ''){
$stmt = $con->prepare("UPDATE $utype SET name = '$uname', pass = '$hashed', state = '$state', city = '$city', inst = '$inst', dep = '$dept',
email = '$email', mob = $mobno, $udata = '$uinfo', `desc` = '$bio' WHERE id = $id");
}
else{
$stmt = $con->prepare("UPDATE $utype SET pic = ?, imgType = ?, name = '$uname', pass = '$hashed', state = '$state', city = '$city', inst = '$inst', dep = '$dept',
email = '$email', mob = $mobno, $udata = '$uinfo', `desc` = '$bio' WHERE id = $id");
$stmt->bind_param("ss", $imageData, $fileType);
}
$stmt->execute();
$stmt->close();
header("location:$location");
?>