How can the data from the $_POST variable be successfully stored in a database after the PayPal payment process is completed?

After the PayPal payment process is completed, you can retrieve the data from the $_POST variable containing the payment details and then insert this data into a database using SQL queries. This can be achieved by establishing a database connection, preparing an INSERT statement, binding the parameters, and executing the query to store the payment information securely in the database.

// Establish database connection
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Prepare and execute SQL query to insert payment details into database
$stmt = $conn->prepare("INSERT INTO payments (payment_id, amount, currency) VALUES (?, ?, ?)");
$stmt->bind_param("sds", $_POST['payment_id'], $_POST['amount'], $_POST['currency']);

if ($stmt->execute()) {
    echo "Payment details stored successfully";
} else {
    echo "Error storing payment details: " . $conn->error;
}

// Close database connection
$stmt->close();
$conn->close();