forked from Astha1404/charvi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAddresses.php
185 lines (184 loc) · 10.5 KB
/
Addresses.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
<!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 require_once 'navbar.php';
if(!isset($_SESSION))
{
session_start();
}
if(!isset($_SESSION['email']))
{
header('Location: /charvi/index.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['saveAddress'];
$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";
echo "<script>window.location.href='Addresses.php?success={$success}'</script>";
}
else
{
$error="Can't Save Your Address Right Now Please Try Again Later";
echo "<script>window.location.href='Addresses.php?error={$error}'</script>";
}
}
if(isset($_POST['removeAddress']))
{
$id = $_POST['removeAddress'];
$sql = "DELETE FROM `address` WHERE ADDRESS_ID = '$id'";
$result = mysqli_query($con,$sql);
unset($_POST);
if($result)
{
$success="Your Address is Saved Successfully";
echo "<script>window.location.href='Addresses.php?success={$success}'</script>";
}
else
{
$error="Can't Save Your Address Right Now Please Try Again Later";
echo "<script>window.location.href='Addresses.php?error={$error}'</script>";
}
}
?>
<div class="container-fluid p-0">
<h1 class="text-center bg-secondary py-4 text-light">Addresses</h1>
<div class="container">
<?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'>
<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']}' required>
</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']}' required>
</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']}' required>
</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']}' required>
</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']}' required>
</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 Pincode`)' 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']}' required>
</div>
</div>
</div>
<div class='card-footer text-center'>
<button type='submit' name='saveAddress' id='{$i}' value='{$row['ADDRESS_ID']}' class='btn btn-success'>Save</button>
<button type='submit' 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'}' required>
</div>
<div class='col'>
<h5 class='d-inline text-nowrap'>Building Name : </h5><input type='text' name='buildingName' id='buildingName' class='form-control' required>
</div>
<div class='col'>
<h5 class='d-inline text-nowrap'>City : </h5><input type='text' name='city' id='city' class='form-control' required>
</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' required>
</div>
<div class='col'>
<h5 class='d-inline text-nowrap'>State : </h5><input type='text' name='state' id='state' class='form-control' required>
</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 Pincode`)' 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']:'')."' required>
</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 fs-4 px-3" href="<?php echo "{$_SERVER['PHP_SELF']}?new={$i}"; ?>">+</a>
</div>
</div>
</div>
<?php
require_once 'userDashboard.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 'footer.php';
?>
</body>
<?php require_once 'scripts.php'; ?>
</html>