37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$projectName = trim($_POST['project_name'] ?? '');
|
|
$tokenName = trim($_POST['token_name'] ?? '');
|
|
$tokenSymbol = trim($_POST['token_symbol'] ?? '');
|
|
|
|
// Basic validation
|
|
if (empty($projectName) || empty($tokenName) || empty($tokenSymbol)) {
|
|
header('Location: index.php?status=error&message=Please+fill+out+all+fields.');
|
|
exit;
|
|
}
|
|
|
|
if (strlen($tokenSymbol) > 10) {
|
|
header('Location: index.php?status=error&message=Token+symbol+cannot+be+longer+than+10+characters.');
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("INSERT INTO projects (project_name, token_name, token_symbol) VALUES (?, ?, ?)");
|
|
$stmt->execute([$projectName, $tokenName, $tokenSymbol]);
|
|
|
|
header('Location: index.php?status=success');
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
// In a real app, you would log this error.
|
|
header('Location: index.php?status=error&message=Database+error.');
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// Redirect if accessed directly
|
|
header('Location: index.php');
|
|
exit;
|