Hi guys. I have just created an intranet in my online store and I'm new at programming so need some help. I'm developing a system that makes this possible: when a user registers, the database detects that they are already a customer who has bought previously and it makes their purchases appear on another page, in this case, in the section of their profile.

I need some help since I don't know how to do it or how to link the php and Mysql code between the registration form and the existing user profile page since it is not a tool that prints the user's data on the same page but rather prints them in another, in the profile section.

Thank you very much in advance! :)

Dani AI

Generated

asked how to detect existing customers at registration and show their past purchases on a separate profile page. is right that a packaged solution is one route; below is a concise, practical way to do it in custom PHP/MySQL so the registration flow links to the profile page correctly.

Keep a nullable user_id on every order plus a guest_email saved at checkout. On registration: normalize the email (trim + strtolower), create the user, then find and attach any orders with the same guest_email that have user_id IS NULL. Do this inside a single transaction to avoid races. Example (PDO):

$pdo->beginTransaction();

$insert = $pdo->prepare('INSERT INTO users (email,password_hash) VALUES (?, ?)');
$insert->execute([$email, password_hash($password, PASSWORD_DEFAULT)]);
$userId = $pdo->lastInsertId();

$update = $pdo->prepare('UPDATE orders SET user_id = ? WHERE guest_email = ? AND user_id IS NULL');
$update->execute([$userId, $email]);

$pdo->commit();

On the profile page require an authenticated session ($_SESSION['user_id']); query orders by user_id and render them. Example fetch:

$stmt = $pdo->prepare('SELECT * FROM orders WHERE user_id = ? ORDER BY created_at DESC');
$stmt->execute([$userId]);
$orders = $stmt->fetchAll();

Security and edge cases: always use prepared statements, hash passwords with password_hash and verify with password_verify (PHP manual). Consider requiring email verification before attaching expensive or sensitive orders. Add a unique index on users.email, store guest_email for any checkout flow, and handle cases where multiple accounts share an email. For high concurrency, consider row-level locking or other safe update patterns. For guidance on secure password storage see the OWASP cheat sheet (Password Storage Cheat Sheet).

What you're looking to do, if I understand you correctly, is to attach a login system to your online store, that shows past purchases to users who are logged in? This is very basic functionality of all ecommerce shops. I would download an existing solution such as Magento and install that. It's an open-source eCommerce platform written in PHP. This should do everything you're wanting, and more, with the least amount of ramp up time. As you become more familiar, and more comfortable, around the Magento code, you can slowly begin to tweak it to add additional functionality to suit your needs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.