voucher system to check if same code used before
Hi. just fine tuning a few bits to my website project.
with the voucher system I have in place, the voucher codes would always be single use since they are unique numbers (gift certificates sold to customers). on the confirm page i have an update transaction so that the voucher code the customer enters is then updated in the database as being "redeemed" and a customer reference ID and date is stored - so thats ok. But I just want to put some validation on the cart.php page (this is where the customer would enter the voucher code) so that if they try and use the same code again a message displays telling them that "voucher code has already been redeemed".
I am stuck to know how I could use form validation to check the state of a field in a table column in the database. IE the field in question "VoucherStatus" is either a "1" (redeemed) or a "0" (unused).
any thoughts how I can tackle this?
further to this problem, there is a logical problem in terms on the voucher status is updated on the confirm page (on page load). but what if the customer changes their mind and continues adding to the cart...if thye had reached the confirm page before this then then updated voucher code wont allow them to use it again (since the voucher status would have been updated on the confirm page)......I did think about putting the voucher update code on the "success" page (after customer goes to paypal to pay for order) but then this can be a problem, because what IF a customer uses a voucher code, then goes to paypal to pay for order BUT then closes their browser - this would mean the success page would never be reached and then the voucher code update will never take place since it would have been on that success page.
any thoughts appriciated on this to :)