-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.php
131 lines (115 loc) · 3.85 KB
/
account.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
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>My Account</title>
<style>
/* CSS styles for the account section */
h2,h3,h4 {
text-align: center;
}
table {
margin: 0 auto;
border-collapse: collapse;
}
th, td {
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
tr:nth-child(even) {
background-color: #f9f9f9;
}
/* CSS styles for the back button */
.back-button {
margin-top: 20px;
text-align: center;
}
.back-button a {
padding: 10px 20px;
background-color: #ff6600;
color: #fff;
text-decoration: none;
border-radius: 5px;
}
.back-button a:hover {
background-color: #ff3300;
}
</style>
</head>
<body>
<?php
if (isset($_SESSION['username'])) {
$username = $_SESSION['username'];
// Connect to the database
$host = 'localhost';
$user = 'root';
$password = ''; // Replace with your actual database password
$database = 'project'; // Replace with your actual database name
$conn = mysqli_connect($host, $user, $password, $database);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Retrieve user's account information from the database
$query = "SELECT username, email, phone_number, address, city, district, state, pincode, (SELECT COUNT(DISTINCT item_id) FROM winners WHERE bidder_name = '$username') AS auctions_won, COUNT(bids.bidder_name) AS bids_made FROM users LEFT JOIN bids ON users.username = bids.bidder_name WHERE username='$username'";
$result = mysqli_query($conn, $query);
if (mysqli_num_rows($result) == 1) {
$row = mysqli_fetch_assoc($result);
$email = $row['email'];
$phone_number = $row['phone_number'];
$address = $row['address'];
$city = $row['city'];
$district = $row['district'];
$state = $row['state'];
$pincode = $row['pincode'];
$auctions_won = $row['auctions_won'] ?? 0;
$bids_made = $row['bids_made'] ?? 0;
// Display user's account information
echo "<h2>My Account</h2>";
echo "<table>";
echo "<tr><th>Username</th><td>$username</td></tr>";
echo "<tr><th>Email</th><td>$email</td></tr>";
echo "<tr><th>Phone Number</th><td>$phone_number</td></tr>";
echo "<tr><th>Address</th><td>$address</td></tr>";
echo "<tr><th>City</th><td>$city</td></tr>";
echo "<tr><th>District</th><td>$district</td></tr>";
echo "<tr><th>State</th><td>$state</td></tr>";
echo "<tr><th>Pincode</th><td>$pincode</td></tr>";
echo "<tr><th>Auctions Won</th><td>$auctions_won</td></tr>";
echo "<tr><th>Bids Made</th><td>$bids_made</td></tr>";
echo "</table>";
} else {
echo "<p>Failed to retrieve account information.</p>";
}
$auction_query = "SELECT item_id, bid_amount FROM winners WHERE bidder_name = '$username'";
$auction_result = mysqli_query($conn, $auction_query);
if (mysqli_num_rows($auction_result) > 0) {
echo "<h3>Auction Won</h3>";
while ($auction_row = mysqli_fetch_assoc($auction_result)) {
$item_id = $auction_row['item_id'];
$winning_price = $auction_row['bid_amount'];
echo "<table>";
echo "<tr><th>Item ID</th><td> $item_id</td>";
echo "<th>Winning Price</th><td>₹$winning_price</td>";
echo "</tr>";
echo "</table>";
}
echo "</td></tr>";
} else {
echo "<h4>No auctions won</h4>";
}
// Close the database connection_aborted
mysqli_close($conn);
} else {
echo "<p>Please log in to view your account.</p>";
}
?>
<div class="back-button">
<a href="home.php">Back to Home</a>
</div>
</body>
</html>