-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserAdded.php
110 lines (110 loc) · 2.93 KB
/
UserAdded.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<html>
<head>
<title>Add User</title>
</head>
<body>
<?php
if(isset($_POST['submit']))//POST method for adding user data from the registar form in registar.php
{
$data_missing = array();
if(empty($_POST['First_Name']))
{
$data_missing[]= 'First Name';
}else
{
$f_name = trim($_POST['First_Name']);
}
if(empty($_POST['Last_Name']))
{
$data_missing[]= 'Last Name';
}else
{
$l_name = trim($_POST['Last_Name']);
}
if(empty($_POST['Email']))
{
$data_missing[]= 'Email';
}else
{
$email = trim($_POST['Email']);
}
if(empty($_POST['Phone_Number']))
{
$data_missing[]= 'Phone Number';
}else
{
$phone = trim($_POST['Phone_Number']);
}
if(empty($_POST['Address']))
{
$data_missing[]= 'Address ';
}else
{
$address = trim($_POST['Address']);
}
if(empty($_POST['City']))
{
$data_missing[]= 'City';
}else
{
$city = trim($_POST['City']);
}
if(empty($_POST['State']))
{
$data_missing[]= 'State';
}else
{
$state = trim($_POST['State']);
}
if(empty($_POST['Zip']))
{
$data_missing[]= 'Zip Code';
}else
{
$zip = trim($_POST['Zip']);
}
if(empty($_POST['userpassword']))
{
$data_missing[]= 'Password';
}else
{
$password = trim($_POST['userpassword']);
}
if($_POST['expiredtime']=="30")
{
$expire=date( strtotime("+30 days"));
}else if($_POST['expiredtime']=="90")
{
$expire=date( strtotime("+90 days"));
}
}
if (!empty($data_missing) == 0)
{
$fshort=substr($f_name,0,1);
$random=rand(1000,9999);
$uniqueID="{$fshort}{$l_name}{$random}";
}
require_once('mysqli_connect.php');
//echo "imhere";
$query="insert into users (First_Name,Last_Name,Email,Phone_Number,Address,City,State,Zip,student_ID,date_entered,userpassword,Expire_Time)
values ('".$f_name."','".$l_name."','".$email."','".$phone."','".$address."','".$city."','".$state."','".$zip."','".$uniqueID."',(UNIX_TIMESTAMP(NOW())),PASSWORD('".$password."'),'".$expire."')";
// echo $query;
$stmt=mysqli_prepare($dbc, $query);
mysqli_stmt_execute($stmt);
$affected_rows = mysqli_stmt_affected_rows($stmt);
if(mysql_affected_rows() == 0)
{
mysqli_stmt_close($stmt);
session_start();
$_SESSION['name']=$uniqueID;
header("location:index.php?added=true");
}else
{
echo'Error Occurred<br />';
echo mysqli_error();
mysqli_stmt_close($stmt);
}
mysqli_close($dbc);
?>
</body>
</html>