File: /home/u756937133/domains/swingersnest.com/public_html/members/index.php
<?php
// Database configuration
$host = 'localhost';
$username = 'u756937133_members'; // default for local development like XAMPP/WAMP
$password = 'GnewP@ss4131#2026L'; // default is usually empty
$database = 'u756937133_members';
// Create connection
$conn = new mysqli($host, $username, $password, $database);
// Fetch members if connection is successful
$result = null;
if (!$conn->connect_error) {
// Handle exports (CSV, JSON, Print)
if (isset($_GET['action'])) {
$action = $_GET['action'];
// Export complete database as CSV
if ($action === 'export_csv') {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="members_full_export.csv"');
$output = fopen('php://output', 'w');
$query = "SELECT * FROM members"; // Complete database
$full_result = $conn->query($query);
if ($full_result && $full_result->num_rows > 0) {
$fields = $full_result->fetch_fields();
$headers = [];
foreach ($fields as $field) {
$headers[] = $field->name;
}
fputcsv($output, $headers);
while ($row = $full_result->fetch_assoc()) {
fputcsv($output, $row);
}
}
fclose($output);
exit();
}
// Fetch all data as JSON for the Copy button
if ($action === 'fetch_all') {
header('Content-Type: application/json');
$query = "SELECT * FROM members"; // Complete database
$full_result = $conn->query($query);
$data = [];
if ($full_result) {
while ($row = $full_result->fetch_assoc()) {
$data[] = $row;
}
}
echo json_encode($data);
exit();
}
// Print all data in a plain table
if ($action === 'print_all') {
$query = "SELECT * FROM members"; // Complete database
$full_result = $conn->query($query);
?>
<!DOCTYPE html>
<html>
<head>
<title>Members Full Database - Print</title>
<style>
body {
font-family: sans-serif;
margin: 20px;
color: #000;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 12px;
}
th,
td {
border: 1px solid #ccc;
padding: 6px;
text-align: left;
}
th {
background-color: #f5f5f5;
}
h2 {
text-align: center;
}
@media print {
body {
margin: 0;
}
}
</style>
</head>
<body onload="window.print()">
<h2>Complete Members Database</h2>
<?php if ($full_result && $full_result->num_rows > 0): ?>
<table>
<thead>
<tr>
<?php
$fields = $full_result->fetch_fields();
foreach ($fields as $field) {
echo "<th>" . htmlspecialchars($field->name) . "</th>";
}
?>
</tr>
</thead>
<tbody>
<?php while ($row = $full_result->fetch_assoc()): ?>
<tr>
<?php foreach ($row as $val): ?>
<td><?php echo htmlspecialchars($val ?: ''); ?></td>
<?php endforeach; ?>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php else: ?>
<p>No records found.</p>
<?php endif; ?>
</body>
</html>
<?php
exit();
}
}
// Pagination settings
$limit = 100;
$page = isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : 1;
if ($page < 1)
$page = 1;
$offset = ($page - 1) * $limit;
// Get total records
$count_sql = "SELECT COUNT(*) as total FROM members";
$count_result = $conn->query($count_sql);
$total_records = $count_result ? $count_result->fetch_assoc()['total'] : 0;
$total_pages = ceil($total_records / $limit);
// Fetch members with pagination
$sql = "SELECT user_id, username, email, full_name, cellphone, admin, register_date FROM members LIMIT $offset, $limit";
$result = $conn->query($sql);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Members Database Preview</title>
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
body {
font-family: 'Inter', sans-serif;
background-color: #f8fafc;
/* slate-50 */
}
</style>
</head>
<body class="min-h-screen p-6 md:p-12">
<div class="max-w-7xl mx-auto">
<!-- Header Section -->
<div class="flex flex-col md:flex-row md:items-center justify-between mb-8">
<div>
<h1 class="text-3xl font-bold text-slate-900 tracking-tight">Members Preview</h1>
<p class="text-slate-500 mt-2">Live view of the `members` database table</p>
</div>
<?php if (!$conn->connect_error && $result): ?>
<div class="mt-4 md:mt-0 flex flex-wrap gap-3">
<!-- Copy Button -->
<button onclick="copyAllData()" id="copyBtn"
class="bg-white text-slate-700 hover:text-blue-600 border border-slate-200 hover:border-blue-300 px-4 py-2.5 rounded-lg font-medium shadow-sm transition-all duration-200 flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round"
d="M15.75 17.25v3.375c0 .621-.504 1.125-1.125 1.125h-9.75a1.125 1.125 0 01-1.125-1.125V7.875c0-.621.504-1.125 1.125-1.125H6.75a9.06 9.06 0 011.5.124m7.5 10.376h3.375c.621 0 1.125-.504 1.125-1.125V11.25c0-4.46-3.243-8.161-7.5-8.876a9.06 9.06 0 00-1.5-.124H9.375c-.621 0-1.125.504-1.125 1.125v3.5m7.5 10.375H9.375a1.125 1.125 0 01-1.125-1.125v-9.25m12 6.625v-1.875a3.375 3.375 0 00-3.375-3.375h-1.5a1.125 1.125 0 01-1.125-1.125v-1.5a3.375 3.375 0 00-3.375-3.375H9.75" />
</svg>
<span>Copy</span>
</button>
<!-- CSV Button -->
<a href="?action=export_csv"
class="bg-white text-slate-700 hover:text-emerald-600 border border-slate-200 hover:border-emerald-300 px-4 py-2.5 rounded-lg font-medium shadow-sm transition-all duration-200 flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round"
d="M3 16.5v2.25A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75V16.5M16.5 12L12 16.5m0 0L7.5 12m4.5 4.5V3" />
</svg>
<span>CSV</span>
</a>
<!-- Print Button -->
<a href="?action=print_all" target="_blank"
class="bg-blue-600 hover:bg-blue-700 text-white px-5 py-2.5 rounded-lg font-medium shadow-md shadow-blue-500/20 transition-all duration-200 flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5"
stroke="currentColor" class="w-5 h-5">
<path stroke-linecap="round" stroke-linejoin="round"
d="M6.72 13.829c-.24.03-.48.062-.72.096m.72-.096a42.415 42.415 0 0110.56 0m-10.56 0L6.34 18m10.94-4.171c.24.03.48.062.72.096m-.72-.096L17.66 18m0 0l.229 2.523a1.125 1.125 0 01-1.12 1.227H7.231c-.662 0-1.18-.568-1.12-1.227L6.34 18m11.318 0h1.091A2.25 2.25 0 0021 15.75V9.456c0-1.081-.768-2.015-1.837-2.175a48.055 48.055 0 00-1.913-.247M6.34 18H5.25A2.25 2.25 0 013 15.75V9.456c0-1.081.768-2.015 1.837-2.175a48.041 48.041 0 011.913-.247m10.5 0a48.536 48.536 0 00-10.5 0v2.796c0 .12.048.234.133.313L7.75 11.25h8.5l.617.617a.443.443 0 00.313-.133V7.284c0-1.081-.768-2.015-1.837-2.175a48.055 48.055 0 00-1.913-.247" />
</svg>
<span>Print Data</span>
</a>
</div>
<?php endif; ?>
</div>
<!-- Connection Error Handling -->
<?php if ($conn->connect_error): ?>
<div class="bg-red-50 border-l-4 border-red-500 p-5 mb-8 rounded-r-lg shadow-sm">
<div class="flex items-start">
<div class="flex-shrink-0">
<svg class="h-6 w-6 text-red-500" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd"
d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z"
clip-rule="evenodd" />
</svg>
</div>
<div class="ml-4">
<h3 class="text-sm font-bold text-red-800">Database Connection Failed!</h3>
<p class="mt-1 text-sm text-red-700">
<strong>Error:</strong> <?php echo $conn->connect_error; ?>
</p>
<p class="mt-2 text-sm text-red-700">
Please make sure your MySQL server is running and the credentials in <code>index.php</code>
(lines 3-5) are correct.
</p>
</div>
</div>
</div>
<?php else: ?>
<!-- Data Table -->
<div class="bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-left text-sm whitespace-nowrap">
<thead class="bg-slate-50 border-b border-slate-200 text-slate-600">
<tr>
<th scope="col"
class="px-6 py-4 font-semibold text-slate-900 uppercase tracking-wider text-xs">User ID
</th>
<th scope="col"
class="px-6 py-4 font-semibold text-slate-900 uppercase tracking-wider text-xs">Profile
</th>
<th scope="col"
class="px-6 py-4 font-semibold text-slate-900 uppercase tracking-wider text-xs">Contact
Info</th>
<th scope="col"
class="px-6 py-4 font-semibold text-slate-900 uppercase tracking-wider text-xs">Role
</th>
<th scope="col"
class="px-6 py-4 font-semibold text-slate-900 uppercase tracking-wider text-xs">Joined
</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 text-slate-700">
<?php if ($result && $result->num_rows > 0): ?>
<?php while ($row = $result->fetch_assoc()): ?>
<tr class="hover:bg-slate-50/80 transition-colors duration-150">
<td class="px-6 py-4 font-mono text-slate-500">
#<?php echo htmlspecialchars($row['user_id']); ?>
</td>
<td class="px-6 py-4">
<div class="flex items-center gap-4">
<div
class="h-10 w-10 rounded-full bg-gradient-to-br from-blue-100 to-indigo-100 flex items-center justify-center text-blue-700 font-bold shadow-inner ring-1 ring-black/5">
<?php echo strtoupper(substr($row['username'], 0, 1) ?: '?'); ?>
</div>
<div>
<div class="font-semibold text-slate-900">
<?php echo htmlspecialchars($row['full_name'] ?: 'No Full Name'); ?>
</div>
<div class="text-slate-500 text-xs mt-0.5">
@<?php echo htmlspecialchars($row['username']); ?>
</div>
</div>
</div>
</td>
<td class="px-6 py-4">
<div class="flex flex-col gap-1">
<div class="flex items-center gap-2 text-slate-700">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-slate-400"
viewBox="0 0 20 20" fill="currentColor">
<path
d="M2.003 5.884L10 9.882l7.997-3.998A2 2 0 0016 4H4a2 2 0 00-1.997 1.884z" />
<path d="M18 8.118l-8 4-8-4V14a2 2 0 002 2h12a2 2 0 002-2V8.118z" />
</svg>
<?php echo htmlspecialchars($row['email'] ?: 'No Email'); ?>
</div>
<div class="flex items-center gap-2 text-slate-500 text-xs">
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 text-slate-400"
viewBox="0 0 20 20" fill="currentColor">
<path
d="M2 3a1 1 0 011-1h2.153a1 1 0 01.986.836l.74 4.435a1 1 0 01-.54 1.06l-1.548.773a11.037 11.037 0 006.105 6.105l.774-1.548a1 1 0 011.059-.54l4.435.74a1 1 0 01.836.986V17a1 1 0 01-1 1h-2C7.82 18 2 12.18 2 5V3z" />
</svg>
<?php echo htmlspecialchars($row['cellphone'] ?: 'No Phone'); ?>
</div>
</div>
</td>
<td class="px-6 py-4">
<?php if ($row['admin'] == 1): ?>
<span
class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-semibold bg-purple-100 text-purple-800 ring-1 ring-inset ring-purple-600/20">
Administrator
</span>
<?php else: ?>
<span
class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-semibold bg-emerald-100 text-emerald-800 ring-1 ring-inset ring-emerald-600/20">
Member
</span>
<?php endif; ?>
</td>
<td class="px-6 py-4 text-slate-500 font-medium whitespace-nowrap">
<?php
// Format date nicely if it exists
$date = $row['register_date'];
echo $date ? date('M j, Y', strtotime($date)) : 'Unknown';
?>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<!-- Empty State -->
<tr>
<td colspan="5" class="px-6 py-16 text-center">
<div class="flex flex-col items-center justify-center text-slate-500">
<div
class="h-16 w-16 bg-slate-100 rounded-full flex items-center justify-center mb-4">
<svg class="h-8 w-8 text-slate-400" fill="none" viewBox="0 0 24 24"
stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
</svg>
</div>
<p class="text-lg font-semibold text-slate-900">No members found</p>
<p class="text-sm mt-1 max-w-sm">We couldn't find any user records in the database.
When you add users, they will appear here.</p>
</div>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
<div
class="bg-slate-50 border-t border-slate-200 px-6 py-4 flex flex-col md:flex-row items-center justify-between gap-4">
<p class="text-xs text-slate-500">
Showing <span class="font-medium text-slate-700">
<?php echo min($offset + 1, $total_records); ?>
</span> to
<span class="font-medium text-slate-700">
<?php echo min($offset + $limit, $total_records); ?>
</span> of
<span class="font-medium text-slate-700">
<?php echo $total_records; ?>
</span> members.
</p>
<?php if ($total_pages > 1): ?>
<nav class="flex items-center gap-1">
<?php if ($page > 1): ?>
<a href="?page=<?php echo $page - 1; ?>"
class="px-3 py-1.5 rounded-md text-sm border border-slate-200 text-slate-600 hover:bg-slate-100 transition-colors">Previous</a>
<?php else: ?>
<span
class="px-3 py-1.5 rounded-md text-sm border border-slate-100 text-slate-400 cursor-not-allowed bg-slate-50">Previous</span>
<?php endif; ?>
<!-- Simple page numbers indicator -->
<span class="px-3 py-1.5 text-sm text-slate-600 font-medium">
Page
<?php echo $page; ?> of
<?php echo $total_pages; ?>
</span>
<?php if ($page < $total_pages): ?>
<a href="?page=<?php echo $page + 1; ?>"
class="px-3 py-1.5 rounded-md text-sm border border-slate-200 text-blue-600 hover:bg-blue-50 hover:border-blue-200 transition-colors font-medium">Next</a>
<?php else: ?>
<span
class="px-3 py-1.5 rounded-md text-sm border border-slate-100 text-slate-400 cursor-not-allowed bg-slate-50">Next</span>
<?php endif; ?>
</nav>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<?php
if (isset($conn)) {
$conn->close();
}
?>
</div>
<!-- JavaScript for Copy Functionality -->
<script>
async function copyAllData() {
const btn = document.getElementById('copyBtn');
const originalContent = btn.innerHTML;
try {
// Show loading state
btn.innerHTML = `<svg class="animate-spin -ml-1 mr-2 h-5 w-5 text-slate-500" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg><span>Copying...</span>`;
btn.disabled = true;
// Fetch the complete database
const response = await fetch('?action=fetch_all');
if (!response.ok) throw new Error('Network response was not ok');
const data = await response.json();
if (data.length === 0) {
alert('No data to copy!');
btn.innerHTML = originalContent;
btn.disabled = false;
return;
}
// Convert JSON to TSV (Tab Separated Values) for easy pasting into Excel/Sheets
const headers = Object.keys(data[0]);
let tsv = headers.join("\t") + "\n";
data.forEach(row => {
const values = headers.map(header => {
let val = row[header];
if (val === null || val === undefined) {
return '';
}
// Clean strings to prevent newlines breaking row format
val = String(val).replace(/\r?\n|\r/g, " ").replace(/\t/g, " ");
return val;
});
tsv += values.join("\t") + "\n";
});
// Copy to clipboard
await navigator.clipboard.writeText(tsv);
// Show success state
btn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5 text-emerald-600"><path stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5" /></svg><span class="text-emerald-700">Copied!</span>`;
btn.classList.add('bg-emerald-50', 'border-emerald-200');
// Revert back after 2 seconds
setTimeout(() => {
btn.innerHTML = originalContent;
btn.classList.remove('bg-emerald-50', 'border-emerald-200');
btn.disabled = false;
}, 2000);
} catch (error) {
console.error('Error copying data:', error);
alert('Failed to copy complete database. Please try again.');
btn.innerHTML = originalContent;
btn.disabled = false;
}
}
</script>
</body>
</html>