prepare("SELECT id FROM users WHERE email = ?"); $stmt->execute([$email]); if ($stmt->fetch()) { die('An account with this email already exists. Log in here.'); } try { $pdo->beginTransaction(); // 1. Create the user $stmt_user = $pdo->prepare( "INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, 'restaurant_owner')" ); $stmt_user->execute([$owner_name, $email, $password]); $user_id = $pdo->lastInsertId(); // 2. Create the restaurant $stmt_restaurant = $pdo->prepare( "INSERT INTO restaurants (name, description, user_id, image_url) VALUES (?, ?, ?, ?)" ); // Using a placeholder image for now $stmt_restaurant->execute([$restaurant_name, $restaurant_description, $user_id, 'assets/images/placeholder.jpg']); $pdo->commit(); // Redirect to a success page or login page header("Location: login.php?signup=success"); exit(); } catch (PDOException $e) { $pdo->rollBack(); // In a real app, you would log this error die("Error creating account: " . $e->getMessage()); }