-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpurchase_pro.php
139 lines (126 loc) · 4.12 KB
/
purchase_pro.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
session_start();
?>
<?php require_once 'include/connection.php';
$cardNameErr = $cardNumberErr = $expiryErr = $cvvErr = "";
function validateCvv($cvv){
if($cvv == '350'){
return true;
} else {
return false;
}
}
function validatecard($number)
{
if($number == '1111-2222-3333-4444'){
return true;
}
return false;
}
// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Get the form data
$name = $_POST['card-name'];
$cardNumber = $_POST['card-number'];
$expiry = $_POST['expiry'];
$cvv = $_POST['cvv'];
$cardType = $_POST['payment-method'];
$amount= $_SESSION["recipePrice"];
// Perform basic form validation
$isValid = true;
if (empty($name)) {
$cardNameErr = "Card Name is required.";
$isValid = false;
}
if (empty($cardNumber)) {
$cardNumberErr = "Card Number is required.";
$isValid = false;
}
else if (validatecard($cardNumber) == false) {
$cardNumberErr = "Invalid Credit Card Number";
$isValid = false;
}
if (empty($expiry)) {
$expiryErr = "Expiry Date is required.";
$isValid = false;
}
if (empty($cvv)) {
$cvvErr = "CVV is required.";
$isValid = false;
} else if(validateCvv($cvv) == false){
$cvvErr = "Incorrect CVV";
$isValid = false;
}
// If there are no errors, process the form
if ($isValid) {
$payment_id = uniqid('payment_');
// Here, you can perform further processing like inserting the data into the database or handling the payment.
$query="INSERT INTO payment(Pay_ID,User_ID,Card_Type,Card_Name,Card_Number,Expiray_Date,CVV,Amount) VALUES ('$payment_id','U1','$cardType', '$name', '$cardNumber', '$expiry', '$cvv','$amount')";
$check = mysqli_query($connection,$query);
// Redirect to a success page
header('Location: boughtpro.php');
exit;
}
}
?>
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Recipe world | Contact us
</title>
<link rel="stylesheet" href="purchase.css">
<script type="text/JavaScript" src="purchase.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="header.css">
<link rel="stylesheet" href="footer.css">
</head>
<body >
<?php include 'header.php';?>
<br><br><br><br><br><br><br><br>
<div class="container">
<h1 style="color:black">Purchase</h1>
<form method="POST" id="creditCardForm">
<div class="form-group">
<label for="payment-method">Payment Method:</label>
<select name="payment-method" id="payment-method">
<option value="visa">Visa</option>
<option value="mastercard">Master Card</option>
<option value="american_express">American Express</option>
</select>
</div>
<div class="form-group">
<label for="name">Card Name:</label>
<input type="text" id="name" name="card-name">
<span class="error"><?php echo $cardNameErr;?></span>
</div>
<div class="form-group">
<label for="card-number">Card Number:</label>
<input type="text" id="card-number" name="card-number">
<span class="error"><?php echo $cardNumberErr;?></span>
</div>
<div class="form-group">
<label for="expiry">Expiry Date:</label>
<input type="date" id="expiry" name="expiry">
<br>
<span class="error"><?php echo $expiryErr;?></span>
</div>
<div class="form-group">
<label for="cvv">CVV:</label>
<input type="text" id="cvv" name="cvv">
<span class="error"><?php echo $cvvErr;?></span>
</div>
<div class="sentence">
<input type="checkbox" value="Check" required>
<p class="p2">I have read and accept the terms of use, rules of flight, and conditions privacy policy</p>
</div>
<button type="submit">Upgrade to Pro Account</button>
</form>
</div>
<br><br>
<?php include 'footer.php';?>
</body>
</html>
<?php mysqli_close($connection);?>