-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha-adduser.php
More file actions
70 lines (51 loc) · 1.91 KB
/
Copy patha-adduser.php
File metadata and controls
70 lines (51 loc) · 1.91 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
<?php
include('connection.php');
session_start();
// create function for generate random password
function randomPassword() {
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
if(isset($_POST['username']))
{
include("connection.php");
$username=$_POST['username'];
$userole=$_POST['userole'];
$position=$_POST['position'];
$created=$_POST['created_by'];
$status=$_POST['status'];
$dc = $_POST['dc'];
$time_created = $_POST['time_created'];
$password = randomPassword();
$check_q = mysqli_query($conn, "select *from `user` where username='$username'");
$check = mysqli_num_rows($check_q);
if($check>0)
{
//NOT SAVED IF ALREADY EXIST
$_SESSION['userexists'] = "Failed to create an account for `$username`! Username already exists. ";
header("Location: x-people.php");
}
else
{
//SAVED ITEM NAME
$insert = mysqli_query($conn, "insert into `user` (username,password,status,userole,position,created_by,dc,time_created) values ('$username','$password','$status','$userole','$position','$created','$dc','$time_created')");
if($insert)
{
$_SESSION['useradded'] = "You have successfully created an account for `$username` ! ";
header("Location: x-people.php");
}
else
{
echo '<script type="text/javascript"> alert("Error Uploading Data!"); </script>';
header("Location: x-people.php");
// when error occur
}
}
}
?>