Check Serial No in MySQL table

Associate
Joined
6 Sep 2005
Posts
244
We're setting up a promotion at work that involves sending cards out to customers with codes on them. The customer logs onto the website, registers their details, then enters the code. They then need to be told what, if anything, they have won.

I have made the first form, where they register details, it inserts that into the table, then sends them to the next page where they enter their code. What i dont know how to do is to get it to check the code against the list in database, and output to the page what they have won. I will also need some way of informing us at the office that someone has entered a code, and if they have won (by email maybe?)

tbh i dont know that much about sql/php, and i may well be over my head here, but i need to get it done :P

Any help would be apreciated as usual

Thanks

Gopher
 
How does the database store the code / prize info?

Lets imagine it's as follows:
Code:
prize_table
code  |   prize   |    winner
1000  |   car     |   
1001  |   boat    | 
1002  |   house   |
What you probably want to do is:
1. Search the database for the code they have entered and make sure no one has already claimed it
Code:
"SELECT * FROM prize_table WHERE code = $code AND winner = NULL"
2. Update that row with the id of the person claiming
 
thanks for that, it helped me sort out another part of the puzzle. i now have the first page for entering contact details, which stores to the DB, and the second page where the code is input, then checked against the table, with the item won being shown on the page.

What i need to figure out now is how to add the customers ID into the prizes table. The ID is automatically created when the new record is posted (so after the submit button is pressed on the first page). I'm assuming i will need to use a session variable to keep the customer ID recorded for the next page, but how do i get it at all if it is none existant until after the submit button is pressed and its gone to page 2? I dont know how i can make a way of refering back to the record from page one while on page 2.

Any ideas or have i ****** up?
 
Why don't you ask them for the code in the registration form? Failing that you can do as you suggested and store their id in a session variable when you insert the user record, then recall it when you want to update the prize record.
 
Back
Top Bottom