简体   繁体   中英

How can I update a user in my DB after a purchase?

<?php

require_once ('vendor/autoload.php');
require_once 'C:\xampp\htdocs\blog\core\init.php';

$_SESSION['user_id'] = 10;

$stripe = array(
"secret_key" => "sk_test_vDYOBYxCErhrgGCeWQJhR4mQ",
"publishable_key" => "pk_test_4mIuE3OsajKO4cnFppcDDISu"
);

\Stripe\Stripe::setApiKey($stripe['secret_key']);

$db = new PDO('mysql:host=127.0.0.1;dbname=blog', 'root', '******');

$userQuery = $db->prepare("
SELECT id, username, email, premium
FROM users
WHERE id = :user_id
");

$sql = "UPDATE users
    SET premium = 1
    WHERE id = :user_id";

$userQuery->execute(['user_id' => $_SESSION['user_id']]);

$user = $userQuery->fetchObject();

?> 

How can I update a certain user after they purchase premium?

This is the only way I could get it to work.

I want to update the user by username or email, but I'm failing. I want it to pull the email/username of the account signed in during a purchase, so it'll update in my database right after & won't update the wrong person, or worse everyone!

The following code will set the variable "premium" to 1 based on a given e-mail address. Note that e-mail needs to be unique, otherwise all users with that e-mail address will become premium

$sql = "UPDATE users
SET premium = 1
WHERE email = :user_email";

$userQuery->execute(['user_email' => $theEMailAddressOfTheUserThatPurchasedPremium]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM