-
Notifications
You must be signed in to change notification settings - Fork 0
/
registerpatientfunc.php
87 lines (76 loc) · 3.3 KB
/
registerpatientfunc.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
<?php
include('config 2.php');
if (!array_key_exists("loginalertmsg",$_SESSION)) {
$_SESSION['loginalertmsg'] = '';
}
?>
<?php
if (isset($_POST['dob'])) {
$birthDate = $_POST['dob'];
$birthDate = explode("-", $birthDate);
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[1], $birthDate[2], $birthDate[0]))) > date("md")
? ((date("Y") - $birthDate[0]) - 1)
: (date("Y") - $birthDate[0]));
if ($age>125) {
$_SESSION['regalertmsg'] = 'Why Your age is Too big?';
header("Location: registerpatient.php"); die();
}
elseif($age<=0){
$_SESSION['regalertmsg'] = 'I think you are not even born now';
header("Location: registerpatient.php"); die();
}
elseif($age<=12){
$_SESSION['regalertmsg'] = "With the help of your parents and book throw the parent's account";
header("Location: registerpatient.php"); die();
}
}
if(isset($_POST['username'])){
$username = $_POST['username'];
$query = "SELECT * FROM loginuser WHERE username='$username'";
$results = $mysqli->query($query);
$num_rows = mysqli_num_rows($results);
if ($num_rows>=1) {
$_SESSION['regalertmsg'] = "Username alreday taken";
header("Location: registerpatient.php"); die();
}elseif($num_rows==0){
$title = isset($_POST['title']) ? $_POST['title'] : '' ;
$gender = isset($_POST['gender']) ? $_POST['gender'] : '' ;
$dob = isset($_POST['dob']) ? $_POST['dob'] : '' ;
$address = isset($_POST['address']) ? $_POST['address'] : '' ;
$contactno = isset($_POST['Contactno']) ? $_POST['Contactno'] : '' ;
$email = isset($_POST['email']) ? $_POST['email'] : '' ;
$password = isset($_POST['password1']) ? $_POST['password1'] : '' ;
$md5password = md5($password);
$username = isset($_POST['username']) ? $_POST['username'] : '' ;
$lname = isset($_POST['lname']) ? $_POST['lname'] : '' ;
$fname = isset($_POST['fname']) ? $_POST['fname'] : '' ;
$characterid = isset($_POST['character']) ? (int)$_POST['character'] : '' ;
$bloodgroup = isset($_POST['bloodgroup']) ? $_POST['bloodgroup'] : '' ;
$healthissue = isset($_POST['healthissue']) ? $_POST['healthissue'] : '' ;
$createdby = 'user';
$currenttime = time();
//echo $username.$characterid.$fname.$lname.$email.$Contactno.$address.$dob.$gender;
$query1 = "INSERT INTO `loginuser` (`username`, `password`, `characterid`, `aprovaladmin`) VALUES ('$username', '$md5password', '$characterid', 1)";
$results1 = $mysqli->query($query1);
$query2 = "INSERT INTO `basicdetailpatient` (`title` , `username`, `characterid`, `firstname`, `lastname`, `email`, `contactno`, `address`, `dob`, `gender`,`bloodgroup`,`healthissue`, `registertimestamp`, `createdby`) VALUES ('$title' , '$username', '$characterid', '$fname', '$lname', '$email', '$contactno', '$address', '$dob', '$gender', '$bloodgroup', '$healthissue', '$currenttime', '$createdby');";
$results2 = $mysqli->query($query2);
if($results1 and $results2){
$_SESSION['user_login_status'] = "alreadylogedin";
$_SESSION['username'] = $username;
$_SESSION['characterid'] = $characterid;
header("Location: PatientProfile.php"); die();
}
else{
if($mysqli->errno=="1062")
{
$_SESSION['regalertmsg'] = "Username alreday taken";
header("Location: registerpatient.php"); die();
}
else
{
echo "<p class='text-danger' style='text-align: center;'> Failed, Could not save!</p>";
}
}
}
}
?>