-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuyNow.php
More file actions
126 lines (114 loc) · 4.78 KB
/
Copy pathbuyNow.php
File metadata and controls
126 lines (114 loc) · 4.78 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
<?php
session_start();
require 'db.php';
$pid = $_GET['pid'];
// Get product details
$sql = "SELECT * FROM fproduct WHERE pid = '$pid'";
$result = mysqli_query($conn, $sql);
$product = mysqli_fetch_assoc($result);
if($_SERVER['REQUEST_METHOD'] == "POST")
{
$name = $_POST['name'];
$city = $_POST['city'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$pincode = $_POST['pincode'];
$addr = $_POST['addr'];
$bid = $_SESSION['id'];
$farmer_id = $product['fid'];
$quantity = 1; // Default quantity
$price = $product['price'];
// First create the order
$sql = "INSERT INTO orders (buyer_id, farmer_id, product_id, quantity, price, status)
VALUES ('$bid', '$farmer_id', '$pid', '$quantity', '$price', 'pending')";
$result = mysqli_query($conn, $sql);
if($result) {
$order_id = mysqli_insert_id($conn);
// Then save the transaction details
$sql = "INSERT INTO transaction (bid, pid, name, city, mobile, email, pincode, addr)
VALUES ('$bid', '$pid', '$name', '$city', '$mobile', '$email', '$pincode', '$addr')";
$result = mysqli_query($conn, $sql);
if($result) {
// Redirect to chat page
header("Location: chat.php?order_id=" . $order_id);
exit();
} else {
$_SESSION['message'] = "Error saving transaction details";
header('Location: Login/error.php');
}
} else {
$_SESSION['message'] = "Error creating order";
header('Location: Login/error.php');
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>AgriLink: Transaction</title>
<meta lang="eng">
<meta charset="UTF-8">
<title>AgriLink</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link href="bootstrap\css\bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="bootstrap\js\bootstrap.min.js"></script>
<!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]-->
<script src="js/jquery.min.js"></script>
<script src="js/skel.min.js"></script>
<script src="js/skel-layers.min.js"></script>
<script src="js/init.js"></script>
<link rel="stylesheet" href="Blog/commentBox.css" />
<noscript>
<link rel="stylesheet" href="css/skel.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/style-xlarge.css" />
</noscript>
</head>
<body>
<?php
require 'menu.php';
?>
<section id="main" class="wrapper" >
<div class="container">
<center>
<h2>Transaction Details</h2>
</center>
<section id="two" class="wrapper style2 align-center">
<div class="container">
<center>
<form method="post" action="buyNow.php?pid=<?= $pid; ?>" style="border: 1px solid black; padding: 15px;">
<center>
<div class="row uniform">
<div class="6u 12u$(xsmall)">
<input type="text" name="name" id="name" value="" placeholder="Name" required/>
</div>
<div class="6u 12u$(xsmall)">
<input type="text" name="city" id="city" value="" placeholder="City" required/>
</div>
</div>
<div class="row uniform">
<div class="6u 12u$(xsmall)">
<input type="text" name="mobile" id="mobile" value="" placeholder="Mobile Number" required/>
</div>
<div class="6u 12u$(xsmall)">
<input type="email" name="email" id="email" value="" placeholder="Email" required/>
</div>
</div>
<div class="row uniform">
<div class="4u 12u$(xsmall)">
<input type="text" name="pincode" id="pincode" value="" placeholder="Pincode" required/>
</div>
<div class="8u 12u$(xsmall)">
<input type="text" name="addr" id="addr" value="" placeholder="Address" style="width:80%" required/>
</div>
</div>
<br />
<p>
<input type="submit" value="Confirm Order" />
</p>
</center>
</form>
</fieldset>