Implementing Member Level Points Redemption in a PHP E‑Commerce Site

This tutorial explains how to create a MySQL members table, configure a PHP database connection, and build backend scripts and a web form that allow e‑commerce users to exchange points for membership level upgrades, complete with full code examples.

php Courses
php Courses
php Courses
Implementing Member Level Points Redemption in a PHP E‑Commerce Site

With the rapid growth of e‑commerce, online malls need features that boost user engagement, such as a member level points redemption system. This article shows how to develop that functionality using PHP.

First, create a MySQL table named members with the fields id (auto‑increment primary key), name (VARCHAR(50)), level (INT), and points (INT) to store member information.

Next, add a config.php file in the project root to hold the database connection settings. The file contains:

<?php
$db_host = 'localhost';
$db_username = 'username';
$db_password = 'password';
$db_name = 'database_name';

$conn = mysqli_connect($db_host, $db_username, $db_password, $db_name);

if (!$conn) {
    die('Database connection failed: ' . mysqli_connect_error());
}
?>

Replace username, password, and database_name with your actual credentials.

Then create redeem_points.php to process the redemption logic. The script starts a session, reads the member ID from the session, and obtains the points and target level from $_POST. It updates the member record with an SQL UPDATE statement:

<?php
session_start();
require 'config.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $member_id = $_SESSION['member_id'];
    $points = $_POST['points'];
    $level = $_POST['level'];

    $sql = "UPDATE members SET points = points - $points, level = $level WHERE id = $member_id";
    $result = mysqli_query($conn, $sql);

    if ($result) {
        echo "Member level points redemption successful!";
    } else {
        echo "Member level points redemption failed: " . mysqli_error($conn);
    }
}
?>

The script uses session_start() to access the logged‑in member ID, reads the submitted data from $_POST, and runs the UPDATE query to adjust points and level.

Finally, create a simple HTML page (also named redeem_points.php) that presents a form for members to enter the points to exchange and the desired level:

<?php require 'config.php'; ?>
<!DOCTYPE html>
<html>
<head>
    <title>Member Level Points Redemption</title>
</head>
<body>
    <h1>Member Level Points Redemption</h1>
    <form method="POST" action="redeem_points.php">
        <label for="points">Points:</label>
        <input type="text" id="points" name="points"><br>
        <label for="level">Level:</label>
        <input type="text" id="level" name="level"><br>
        <input type="submit" value="Redeem">
    </form>
</body>
</html>

The page includes the configuration file, displays a form, and submits the data to the same script for processing.

By following these steps, you have a complete member level points redemption feature that lets e‑commerce users exchange points for higher membership levels, encouraging more purchases and increasing user retention.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

e‑commercemysqlWeb DevelopmentPHPPoints Redemption
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.