I work for a company that does online coupons. We'd like to restrict the printing of coupons to only those people who have not printed them before. I'm doing this by inserting couponid numbers and ip addresses to a Print Tracking table.
My plan is upon using the print button, a php script checks the MySQL db for records containing the exact couponid and ip address. When it finds a match it echoes "You have already used this coupon, please choose another"
If no match is found, a new record is created with the couponid and ip address and the user is granted access to the coupon page. Now that the user's ip address along with the couponid is stored, they should not be able to return from the same IP address and print the same coupon.
I am new to IF and ELSE statements. Thanks in advance.
Here is my code:
<?php
// connect to db
mysql_connect("xxxxxx", "xxxxxx", "xxxxxx") or die(mysql_error()) ;
mysql_select_db("xxxxxx") or die(mysql_error()) ;
// grab user ip
$ip = $_SERVER['REMOTE_ADDR'];
echo $ip;
$result = mysql_query("SELECT coupid, ip FROM print_tracking");
while($row = mysql_fetch_array($result))
{
echo $row['coupid'] . " " . $row['ip'];
echo "<br />";
}
if ( $row['coupid'] = $row_rcdCoupons['coupid'] AND $row['ip'] = "$ip" )
echo "You have already printed this coupon, please choose another.";
else
echo "Thank You.";
mysql_query("INSERT INTO print_tracking (coupid, ip)
VALUES ('$row_rcdCoupons[coupid]', '$ip')");
?>