-
Notifications
You must be signed in to change notification settings - Fork 1
/
signUpBuyerExe.php
122 lines (102 loc) · 4.39 KB
/
signUpBuyerExe.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
111
112
113
114
115
116
117
118
119
120
121
122
<?php
include 'db.php';
session_start();
$pDatabase = Database::getInstance(); // ye db.php wale class ka object
// define variables and set to empty values
$fname=$address=$gender=$age=$phone=$email=$pwd="";
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$fname = test_input($_POST["name"]);
$address = test_input($_POST["address"]);
$gender = test_input($_POST["gender"]);
$age = test_input($_POST["age"]);
$phone = test_input($_POST["cno"]);
$email = test_input($_POST["email"]);
$pwd = test_input($_POST["pwd"]);
$cpwd = test_input($_POST["cnfpwd"]);
if($pwd==$cpwd)
{
$t= "SELECT * from buyer_register where name='$fname' and phone='$phone'"; //duplicate primary key entry btata h
$q = $pDatabase->query($t);
$r=mysqli_num_rows($q);
if($r==0)
{
$rand=mt_rand(100000,1000000);
//otp mail generation
require 'PHPMailerAutoload.php';
require 'credential.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = EMAIL; // SMTP username
$mail->Password = PASS; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom(EMAIL, 'Yound minds ');
$mail->addAddress($email); // Add a recipient
// Name is optional
$mail->addReplyTo(EMAIL);
// Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'OTP Verification Mail';
$mail->Body = '<div>This is the verification mail Go to login page and login with your credentials and then enter OTP. <br>Click on this link: <a href="localhost/minor/profile_buyer/loginBuyer.php">localhost/minor/profile_buyer/loginBuyer.php</a> <br> Your OTP is <b>'.$rand.'</b> Enter this to activate your account on Young mind Bikes</div>';
//$mail->AltBody = $_POST['message'];
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
//register table
$pa= "INSERT INTO `buyer_register`(`name`, `address`, `age`, `gender`, `phone`, `mail`, `password`) VALUES ('$fname','$address','$age','$gender','$phone','$email','$pwd')" or die(mysql_error());
//login table
$pa1="INSERT INTO `login_buyer`(`email`, `password`) VALUES ('$email','$pwd')" or die(mysql_error());
//otp table
//$pa2="INSERT INTO `verification_buyer`(`ID`, `email`, `OTP`, `flag`) VALUES ('','$email','$rand','')";
$p=$pDatabase->query($pa); //ye query function db.php m h jisse query run krwa rhe h. $pa query h aur isko hmlg query function m bhej rhe h
$p1=$pDatabase->query($pa1);
$sel="SELECT `ID` FROM `buyer_register` WHERE mail='$email'";
$res=$pDatabase->query($sel);
$row=mysqli_fetch_assoc($res);
echo $id=$row['ID'];
//otp table
$pa2="INSERT INTO `verification_buyer`(`ID`, `email`, `OTP`, `flag`) VALUES ('$id','$email','$rand','')";
$p2=$pDatabase->query($pa2);
if($p && $p1 && $p2)
{
?>
<script>
if(confirm("you have successfully registered,do you want to register more?"))
{
window.location="signUpBuyer.php";
}
else
{
window.location="profile_buyer/loginBuyer.php";
}
</script>
<?php
}
}
else
{
echo'<script>window.location="signUpBuyer.php";
alert("Already registered!!");
</script>';
}
}
else
{
echo '<script>alert("Password not matched Try again !!!");
window.location="signUpBuyer.php";</script>';
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>