forked from Astha1404/charvi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchooseAddress.php
206 lines (203 loc) · 11.4 KB
/
chooseAddress.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<?php require_once 'header.php'; ?>
</head>
<body>
<?php
if(!isset($_SESSION))
{
session_start();
}
if(!isset($_SESSION['email']))
{
header('Location: /charvi/index.php');
}
require_once 'dbconnection.php';
if(isset($_POST['saveAddress']))
{
$hno = $_POST['houseNo'];
$bname = $_POST['buildingName'];
$city = $_POST['city'];
$area = $_POST['area'];
$state = $_POST['state'];
$landmark = $_POST['landmark'];
$pincode = $_POST['pincode'];
$userId = $_SESSION['userId'];
$id = $_POST['temp'];
$sql = "SELECT * FROM address WHERE address_id = '{$id}'";
$result = mysqli_query($con,$sql);
unset($_POST);
if(mysqli_num_rows($result)==0)
{
$sql = "INSERT INTO `address`(`ADDRESS_ID`, `HOUSE_NO`, `BUILDING_NAME`, `CITY`, `AREA`, `STATE`, `LANDMARK`, `PINCODE`, `USER_ID`) VALUES (NULL,'{$hno}','{$bname}','{$city}','{$area}','{$state}','{$landmark}','{$pincode}','{$userId}')";
}
else
{
$sql = "UPDATE `address` SET `HOUSE_NO`='{$hno}',`BUILDING_NAME`='{$bname}',`CITY`='{$city}',`AREA`='{$area}',`STATE`='{$state}',`LANDMARK`='{$landmark}',`PINCODE`='{$pincode}' WHERE address_id = {$id} AND user_id = {$userId}";
}
$result = mysqli_query($con,$sql);
if($result)
{
$success="Your Address is Saved Successfully";
header("Location: /charvi/chooseAddress.php?success={$success}");
}
else
{
$error="Can't Save Your Address Right Now Please Try Again Later";
header("Location: /charvi/chooseAddress.php?error={$error}");
}
}
if(isset($_POST['removeAddress']))
{
$id = $_POST['temp'];
$sql = "DELETE FROM `address` WHERE ADDRESS_ID = '$id'";
$result = mysqli_query($con,$sql);
unset($_POST);
if($result)
{
$success="Your Address is Removed Successfully";
header("Location: /charvi/chooseAddress.php?success={$success}");
}
else
{
$error="Can't Remove Your Address Right Now Please Try Again Later";
header("Location: /charvi/chooseAddress.php?error={$error}");
}
}
if(isset($_POST['checkOutAddress']))
{
$sql = "UPDATE cart SET address_id = {$_POST['checkOutAddress']} WHERE user_id = {$_SESSION['userId']}";
$result = mysqli_query($con,$sql);
if($result)
{
header("Location: /charvi/checkout.php");
}
else
{
header("Location: /charvi/index.php?error=Can't Place Order Now");
}
}
require 'navbar.php';
?>
<div class="container-fluid p-0">
<h1 class="text-center bg-secondary py-4 text-light">Choose Delivery Address</h1>
<div class="container">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php
$sql = "SELECT * FROM `address` WHERE user_id = {$_SESSION['userId']}";
$result = mysqli_query($con,$sql);
$i=1;
while(($row = mysqli_fetch_assoc($result)))
{
echo "<div class='card my-2'>
<form action='{$_SERVER['PHP_SELF']}' method='POST'>
<input type='number' name='temp' style='display:none;' value='{$row['ADDRESS_ID']}'>
<div class='card-header'><h4 class='text-center'>Address {$i}</h4></div>
<div class='card-body'>
<div class='row justify-content-center align-items-center my-2'>
<div class='col'>
<h5 class='d-inline text-nowrap'>House Number : </h5><input type='text' name='houseNo' id='houseNo' class='form-control' value='{$row['HOUSE_NO']}'>
</div>
<div class='col'>
<h5 class='d-inline text-nowrap'>Building Name : </h5><input type='text' name='buildingName' id='buildingName' class='form-control' value='{$row['BUILDING_NAME']}'>
</div>
<div class='col'>
<h5 class='d-inline text-nowrap'>City : </h5><input type='text' name='city' id='city' class='form-control' value='{$row['CITY']}'>
</div>
</div>
<div class='row justify-content-center align-items-center my-2'>
<div class='col'>
<h5 class='d-inline text-nowrap'>Area : </h5><input type='text' name='area' id='area' class='form-control' value='{$row['AREA']}'>
</div>
<div class='col'>
<h5 class='d-inline text-nowrap'>State : </h5><input type='text' name='state' id='state' class='form-control' value='{$row['STATE']}'>
</div>
<div class='col'>
<h5 class='d-inline text-nowrap'>Pincode : </h5><input type='number' min='100000' max='999999' class='form-control' id='pincode' name='pincode' oninvalid='this.setCustomValidity(`Please Enter Valid Mobile Number`)' oninput='this.setCustomValidity(``)' value='{$row['PINCODE']}' required>
</div>
</div>
<div class='row my-2'>
<div class='col'>
<h5 class='d-inline text-nowrap'>Landmark : </h5><input type='text' name='landmark' class='form-control' value='{$row['LANDMARK']}'>
</div>
</div>
</div>
<div class='card-footer text-center'>
<button type='submit' name='checkOutAddress' id='{$i}' value='{$row['ADDRESS_ID']}' class='btn btn-primary'>Deliver Here</button>
<button type='submit' name='saveAddress' id='{$i}' value='{$row['ADDRESS_ID']}' class='btn btn-success'>Save</button>
<button type='' name='removeAddress' id='{$i}' value='{$row['ADDRESS_ID']}' class='btn btn-danger removeAddress'>Remove</button>
</div>
</form>
</div>";
$i++;
}
if(isset($_GET['new']))
{
echo "<div class='card'>
<form action='{$_SERVER['PHP_SELF']}' method='POST'>
<input type='number' name='temp' style='display:none;' value=''>
<div class='card-header'><h4 class='text-center'>Address {$i}</h4></div>
<div class='card-body'>
<div class='row justify-content-center align-items-center my-2'>
<div class='col'>
<h5 class='d-inline text-nowrap'>House Number : </h5><input type='text' name='houseNo' id='houseNo' class='form-control'}'>
</div>
<div class='col'>
<h5 class='d-inline text-nowrap'>Building Name : </h5><input type='text' name='buildingName' id='buildingName' class='form-control'>
</div>
<div class='col'>
<h5 class='d-inline text-nowrap'>City : </h5><input type='text' name='city' id='city' class='form-control'>
</div>
</div>
<div class='row justify-content-center align-items-center my-2'>
<div class='col'>
<h5 class='d-inline text-nowrap'>Area : </h5><input type='text' name='area' id='area' class='form-control'>
</div>
<div class='col'>
<h5 class='d-inline text-nowrap'>State : </h5><input type='text' name='state' id='state' class='form-control'>
</div>
<div class='col'>
<h5 class='d-inline text-nowrap'>Pincode : </h5><input type='number' min='100000' max='999999' class='form-control' id='pincode' name='pincode' oninvalid='this.setCustomValidity(`Please Enter Valid Mobile Number`)' oninput='this.setCustomValidity(``)' required>
</div>
</div>
<div class='row my-2'>
<div class='col'>
<h5 class='d-inline text-nowrap'>Landmark : </h5><input type='text' name='landmark' class='form-control' value='".(isset($row)?$row['LANDMARK']:'')."'>
</div>
</div>
</div>
<div class='card-footer text-center'>
<button type='submit' name='saveAddress' id='{$i}' value='".(isset($row)?$row['ADDRESS_ID']:'')."' class='btn btn-success'>Save</button>
</div>
</form>
</div>";
}
?>
<div class="container d-flex justify-content-end my-4">
<a class="btn rounded-circle btn-primary" href="<?php echo "{$_SERVER['PHP_SELF']}?new={$i}"; ?>">+</a>
</div>
</form>
</div>
</div>
<?php
if(isset($_GET['error']))
{
$error = $_GET['error'];
require_once 'error.php';
}
if(isset($_GET['success']))
{
$error = $_GET['success'];
require_once 'success.php';
}
require_once 'userDashboard.php';
require_once 'footer.php';
?>
</body>
<?php require_once 'scripts.php'; ?>
</html>