File Manager
Editing: register.php
<?php // Enable error reporting for debugging ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); require_once 'google-config.php'; $login_url = $client->createAuthUrl(); $host = "127.0.0.1:3306"; $username = "u404542307_dacotywebsites"; $password = "daCotywebs1te5"; $database = "u404542307_eizon"; try { // Establish database connection $pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { die("Could not connect to the database: " . $e->getMessage()); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { // Capture and sanitize form inputs $username = trim($_POST['username'] ?? ''); $username = preg_replace('/[^a-zA-Z0-9 _-]/', '', $username); // only allow letters, numbers, space, _ and - $username = trim($username); // remove leading/trailing spaces again if (empty($username)) { throw new Exception('Invalid or empty username.'); } $email = trim(filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL)); $password = trim($_POST['password']); // Basic input validation (STRICTER CHECKS) if (empty($username) || ctype_space($username)) { throw new Exception('Username cannot be empty or just spaces.'); } if (empty($email)) { throw new Exception('Email cannot be empty.'); } if (empty($password)) { throw new Exception('Password cannot be empty.'); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new Exception('Invalid email format.'); } if (!preg_match('/^[a-zA-Z0-9 _-]+$/', $username)) { throw new Exception('Invalid username. Only letters, numbers, underscores, and hyphens are allowed.'); } if (strlen($password) < 6) { throw new Exception('Password must be at least 6 characters long.'); } // Hash the password securely $hashed_password = password_hash($password, PASSWORD_BCRYPT); // Check if username exists (in profiles table) $checkUsernameQuery = "SELECT COUNT(*) FROM profiles WHERE username = :username"; $stmt = $pdo->prepare($checkUsernameQuery); $stmt->bindParam(':username', $username, PDO::PARAM_STR); $stmt->execute(); if ($stmt->fetchColumn() > 0) { throw new Exception('Username is already registered. Please use a different username.'); } // Check if email exists (in users table) $checkEmailQuery = "SELECT COUNT(*) FROM users WHERE email = :email"; $stmt = $pdo->prepare($checkEmailQuery); $stmt->bindParam(':email', $email, PDO::PARAM_STR); $stmt->execute(); if ($stmt->fetchColumn() > 0) { throw new Exception('Email is already registered. Please use a different email.'); } // Insert into users table // $insertQuery = "INSERT INTO users (email, password) VALUES (:email, :password)"; $insertQuery = "INSERT INTO users (username, email, password) VALUES (:username, :email, :password)"; $stmt = $pdo->prepare($insertQuery); $stmt->bindParam(':username', $username, PDO::PARAM_STR); $stmt->bindParam(':email', $email, PDO::PARAM_STR); $stmt->bindParam(':password', $hashed_password, PDO::PARAM_STR); if ($stmt->execute()) { $userId = $pdo->lastInsertId(); // DEBUG: Check username before insertion error_log("Inserting username: " . $username); // Store user info in session $_SESSION['user_id'] = $userId; $_SESSION['username'] = $username; $_SESSION['email'] = $email; // Redirect to edit_profile.php header("Location: edit_profile.php"); exit; } else { throw new Exception('Failed to register user. Please try again.'); } } catch (Exception $e) { echo "<script>alert('" . addslashes($e->getMessage()) . "'); window.location.href='register.php';</script>"; exit; } } ?> <!DOCTYPE html> <html lang="en"> <head> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-Z6RR2PMZW4"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-Z6RR2PMZW4'); </script> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>eizon-sign-up</title> <meta name="description" content="Join eizon today! Create an account to buy, sell, and connect with users in your region. It's quick, easy, and free to sign up."> <link rel="stylesheet" href="accounts.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css"> <link rel="manifest" href="/manifest.json"> <style> .login { background-color: #24e037; color: white; padding: 15px 20px; border: none; border-radius: 5px; font-size: 16px; width:99%; margin:auto; font-weight:900; margin-top:10px; position: relative; } .loginlink { width: 50%; margin: auto; } @media (max-width: 768px) { .loginlink { width: 99%; } } </style> </head> <body> <div class="google"> <form class="form" id="registerForm" method="post"> <h1>e!zon</h1> <p>WELCOME TO EIZON</p> <input type="text" name="username" id="username" placeholder="Name of business" required><br> <input type="email" name="email" id="email" placeholder="Enter your email" required><br> <input type="password" name="password" id="password" placeholder="Create password" required><br> <button type="submit">Register</button> <p>Already have an account? <a href="/login">Login!</a></p> </form> <div class="loginlink"> <a href="<?php echo htmlspecialchars($login_url); ?>"> <button class="login"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48" width="20px" height="20px" style="vertical-align: middle; margin-right: 10px;"> <path fill="#EA4335" d="M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z"/> <path fill="#4285F4" d="M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z"/> <path fill="#FBBC05" d="M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z"/> <path fill="#34A853" d="M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z"/> <path fill="none" d="M0 0h48v48H0z"/> </svg> CONTINUE WITH GOOGLE </button> </a> </div> </div> <script> document.getElementById('registerForm').addEventListener('submit', function (e) { const username = document.getElementById('username').value.trim(); const email = document.getElementById('email').value.trim(); const password = document.getElementById('password').value.trim(); const usernameRegex = /^[a-zA-Z0-9 _-]+$/; if (!username || !email || !password) { alert("All fields are required."); e.preventDefault(); } else if (!usernameRegex.test(username)) { alert("Invalid username. Only letters, numbers, spaces, underscores, and hyphens are allowed."); e.preventDefault(); } else if (!/\S+@\S+\.\S+/.test(email)) { alert("Invalid email format."); e.preventDefault(); } else if (password.length < 6) { alert("Password must be at least 6 characters long."); e.preventDefault(); } }); </script> </body> </html>
💾 Save
⬅ Back