This doesn’t seem to work. Basically, every authorized user has a unique download code. They enter it in a form and submit. If the code exists in the DB, a file is automatically downloaded. This works with the awesome help of @PHPNob. Now I want to extend it so if the code is found in the DB, it downloads as usual, but also then changes the code to something else so the user won’t go around spreading the link and code.
Here is what I have. It doesn’t do anything except refresh the page and the validation ($error) is also now broken.
Can I get some pointers? Thanks!!
if (isset($_GET['code']) && !empty($_GET['code'])) {
$stmt = $db_donate->prepare('SELECT * FROM donations WHERE code = ?');
$stmt->bind_param('s', $code);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows>0) {
if ($stmt = $db_donate->prepare('UPDATE donations SET code = ?')) {
$newcode = 'downloaded';
$stmt->bind_param('ss', $newcode, $_GET['code']);
$stmt->execute();
run code
}
} else {
$error = "<span class='error_msg'>Download code not found or file already downloaded!</span>";
}
}