I have a database with 2 tables that I need to access/potentially modify. One table has a list of products (table name "product"), and information for each. The other stores identifying information for people who redeem a code for a product (table name "redeem").
Each product has a unique claim code associated with it, and is stored in the product's "location" column in the "product" table. I have a form, where individuals can enter their name (first & last), email address, and a claim code. The first person to enter the claim code for a particular product "wins" it. As soon as someone wins a product, I want their name, email, and claim code to be saved in the "redeem" table of the database, as well as a "success" message displayed to the user.
Any subsequent users who try to enter the same code, should receive an "error" message stating that the product has already been claimed, and nothing should be saved to the DB.
If anyone enters an invalid claim code (i.e. a code that is not associated with any particular product), they should receive an error message stating that they entered an incorrect code. Also, nothing should be saved to the DB.

PHP code I have so far is:
Code PHP:
  $first_name = $_POST['f_name'];
  $last_name = $_POST['l_name'];
  $email = $_POST['e_mail'];
  $verification = $_POST['v_code'];
  $dbc = mysql_connect('localhost','db','pw')
    or die('Could not connect: ' . mysql_error());
  $query = "INSERT INTO redeem (f_name, l_name, e_mail, v_code) " .
    "VALUES ('$first_name', '$last_name', '$email', '$verification')";
  if(mysql_query("SELECT location FROM product WHERE location = '$verification'")){
	if(mysql_query("SELECT v_code FROM redeem WHERE v_code = '$verification'")){
          echo 'Sorry, this item has already been redeemed.';
  }else{ $result = mysql_query($dbc, $query)
    or die('Error querying database.');
	echo 'Sorry, you have entered an incorrect claim code. Please use your browser\'s back button to try again.';

Right now, no matter what I enter in the form that is passed to this script, the message I receive is "Sorry, you have entered an incorrect claim code. Please use your browser's back button to try again."

I'm sure there's a better way - especially since there seems to be 3 separate queries going on. Is there a way to simplify the query/some other way to do this?