In the function below after running the function its inserting into user table but wont insert into the usage table
function Signup($username, $password, $member) {
global $dbs;
try {
// Generate API Key using JWT
require_once 'JWT_class.php';
$token = array();
$token['id'] = uniqid(); // Generating a unique ID for API Key
$apiKey = JWT::encode($token, 'secret_server_key');
// Calculate Premium date based on member type
$premiumDate = ($member == 1) ? date('Y-m-d', strtotime('+30 days')) : date('Y-m-d');
$query = "INSERT INTO user (username, password, memberType, APIKey) VALUES (:username, :password, :memberType, :APIKey)";
$statement = $dbs->prepare($query);
$statement->bindValue(":username", $username);
$statement->bindValue(":password", $password);
$statement->bindValue(":memberType", $member);
$statement->bindValue(":APIKey", $apiKey); // Insert API Key value
$statement->execute();
// Insert usage data into usage table
$usageQuery = "INSERT INTO usage (APIKey, todaysUsage, UsageDate, PremiumDate) VALUES (:APIKey, 0, CURDATE(), :premiumDate)";
$usageStatement = $dbs->prepare($usageQuery);
$usageStatement->bindValue(":APIKey", $apiKey);
$usageStatement->bindValue(":premiumDate", $premiumDate);
$usageStatement->execute();
$rowCount = $statement->rowCount();
if ($rowCount < 0) {
return true;
} else {
return false;
}
} catch (PDOException $ex) {
// Handle the error gracefully, log, or display an appropriate message
header("Location:../view/error.php?msg=" . $ex->getMessage());
}
}
The database code is
CREATE TABLE `usage` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`APIKey` varchar(999) NOT NULL,
`todaysUsage` int(11) NOT NULL,
`UsageDate` date NOT NULL,
`PremiumDate` date NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `APIKey_UNIQUE` (`APIKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
I tried debugging by adding the code below to the end but am not getting any visible output,
$usageStatement->execute();
$usageErrorInfo = $usageStatement->errorInfo();
if ($usageErrorInfo[0] !== '00000') {
print_r($usageErrorInfo); // Debugging output
}