investment platform
investment platform
USE investment_platform;
register.php-
<?php
$conn = new mysqli("localhost", "root", "", "investment_platform");
if ($stmt->execute()) {
echo "Registration successful.";
} else {
echo "Error: Could not register user.";
}
}
?>
<h2>Register</h2>
<form method="post">
<label>Username: <input type="text" name="username" required></label><br>
<label>Password: <input type="password" name="password" required></label><br>
<button type="submit">Register</button>
</form>
login.php-
<?php
session_start();
$conn = new mysqli("localhost", "root", "", "investment_platform");
<h2>Login</h2>
<form method="post">
<label>Username: <input type="text" name="username" required></label><br>
<label>Password: <input type="password" name="password" required></label><br>
<button type="submit">Login</button>
</form>
dashboard.php-
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
<h2>Your Accounts</h2>
<form method="post" action="transaction.php">
<label>Select Account:
<select name="account_id">
<?php while ($account = $accounts->fetch_assoc()): ?>
<option value="<?= $account['id'] ?>"><?=
ucfirst($account['account_type']) ?> (Balance: $<?= $account['balance']
?>)</option>
<?php endwhile; ?>
</select>
</label><br>
<label>Transaction Type:
<select name="transaction_type">
<option value="deposit">Deposit</option>
<option value="withdrawal">Withdrawal</option>
</select>
</label><br>
<label>Amount: <input type="number" name="amount" step="0.01" min="0.01"
required></label><br>
<button type="submit">Submit Transaction</button>
</form>
transaction.php-
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
$account_id = $_POST['account_id'];
$transaction_type = $_POST['transaction_type'];
$amount = (float) $_POST['amount'];
// Record transaction
$stmt = $conn->prepare("INSERT INTO transactions (account_id, transaction_type,
amount) VALUES (?, ?, ?)");
$stmt->bind_param("isd", $account_id, $transaction_type, $amount);
$stmt->execute();
transaction history-
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
// Fetch transactions
$transactions = $conn->query("SELECT t.transaction_date, a.account_type,
t.transaction_type, t.amount
FROM transactions t
JOIN accounts a ON t.account_id = a.id
WHERE a.user_id = $user_id
ORDER BY t.transaction_date DESC");
?>
<h2>Transaction History</h2>
<table border="1">
<tr>
<th>Date</th>
<th>Account Type</th>
<th>Transaction Type</th>
<th>Amount</th>
</tr>
<?php while ($transaction = $transactions->fetch_assoc()): ?>
<tr>
<td><?= $transaction['transaction_date'] ?></td>
<td><?= ucfirst($transaction['account_type']) ?></td>
<td><?= ucfirst($transaction['transaction_type']) ?></td>
<td>$<?= $transaction['amount'] ?></td>
</tr>
<?php endwhile; ?>
</table>