-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrechargefunction.php
More file actions
151 lines (138 loc) · 5.75 KB
/
Copy pathrechargefunction.php
File metadata and controls
151 lines (138 loc) · 5.75 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
session_start();
require_once('dbconfig.php');
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
$smtp_host = "server199.web-hosting.com";
$smtp_port = 465;
$smtp_username = "bank@vannivogue.com";
$smtp_password = "unipassword@1234ABC";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$pin = $_POST["pin"];
if (!preg_match("/^\d+$/", $pin)) {
echo '<script>alert("Please enter only digits for PIN."); window.location.href = "recharge.php";</script>';
exit;
}
$userAccountNumber = $_SESSION['user'];
$checkCardQuery = "SELECT * FROM newlycreatedcards WHERE cardnumber = '$pin'";
$result = $conn->query($checkCardQuery);
if ($result->num_rows == 0) {
echo '<script>alert("Invalid Card Number."); window.location.href = "recharge.php";</script>';
exit;
}
$checkUsedQuery = "SELECT * FROM newlycreatedcards WHERE cardnumber = '$pin' AND usedby IS NOT NULL";
$result = $conn->query($checkUsedQuery);
if ($result->num_rows > 0) {
echo '<script>alert("This scratch card is already used."); window.location.href = "recharge.php";</script>';
exit;
}
$getValueQuery = "SELECT value FROM newlycreatedcards WHERE cardnumber = '$pin'";
$result = $conn->query($getValueQuery);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$cardValue = $row['value'];
} else {
echo '<script>alert("Error retrieving scratch card value."); window.location.href = "recharge.php";</script>';
exit;
}
$updateUsedQuery = "UPDATE newlycreatedcards SET usedby = '$userAccountNumber' WHERE cardnumber = '$pin'";
$conn->query($updateUsedQuery);
$getUserBalanceQuery = "SELECT balance FROM user WHERE accountNumber = '$userAccountNumber'";
$result = $conn->query($getUserBalanceQuery);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$userBalance = $row['balance'];
} else {
echo '<script>alert("Error retrieving user balance."); window.location.href = "recharge.php";</script>';
exit;
}
$newBalance = $userBalance + $cardValue;
$updateUserBalanceQuery = "UPDATE user SET balance = $newBalance WHERE accountNumber = '$userAccountNumber'";
$conn->query($updateUserBalanceQuery);
$useremailQuery = "SELECT email FROM user WHERE accountNumber = '$userAccountNumber'";
$getValueQuery = "SELECT value FROM newlycreatedcards WHERE cardnumber = '$pin'";
$result = $conn->query($getValueQuery);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$getcardvalue = $row['value'];
} else {
echo '<script>alert("Error retrieving scratch card value."); window.location.href = "recharge.php";</script>';
exit;
}
$getuseremail= $conn->query($useremailQuery);
$userData = $getuseremail->fetch_assoc();
$userEmail = $userData['email'];
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = $smtp_host;
$mail->Port = $smtp_port;
$mail->SMTPAuth = true;
$mail->Username = $smtp_username;
$mail->Password = $smtp_password;
$mail->SMTPSecure = 'ssl';
$mail->setFrom($smtp_username, 'Account Top Up');
$mail->addAddress($userEmail);
$mail->Subject = 'You Have Succesfully Recharge your bank account';
$mail->isHTML(true);
$mail->Body = '<html>
<head>
<title></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<style>
/* Define your styles here */
body {
background-color: #f7f7f7;
color: #333333;
font-family: Arial, sans-serif;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #ffffff;
border-radius: 5px;
box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #5555ff;
}
p {
margin-bottom: 20px;
}
.button {
display: inline-block;
padding: 15px 30px;
background-color: #5555ff;
color: #ffffff;
text-decoration: none;
border-radius: 5px;
font-size: 18px;
}
</style>
</head>
<body>
<div class="container">
<h1>Deposit Successful</h1>
<p>Dear Customer,</p>
<p>You have successfully deposited LKR'.$getcardvalue.' to your bank account '.$userAccountNumber.'.</p>
<p>Thank you for choosing our services.</p>
<p>Best regards,<br>The Bank Team</p>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>';
/*$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Set to `SMTP::DEBUG_OFF` for production
$mail->Debugoutput = function ($str, $level) {
echo "debug level $level; message: $str";
};*/
$mail->send();
session_unset();
session_destroy();
echo '<script>alert("Recharge successful."); window.location.href = "index.php";</script>';
exit;
}
$conn->close();
?>