Here's another twist to produce a descending #
Hey b,
Here is another way to do it.
In your DB make the default value for the coup_use table 3. We'll just count backwards.
Then use the Dreamweaver built-in update behavior to update the coupon. The behavior will be created in a Wizard and placed on your page at the right place, most likely. I would need to see the all the page code to be sure.
You will then want to use the Submit Button for that update to be the button the user pushes to validate their coupon.
Here is the update code you need - it goes near the top, but under $theValue switch()'s code generated by Dreamweaver, also under the start_session() stuff:
<?php
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE visitors SET coup_use=-1 WHERE VisitorID=%s",
GetSQLValueString($_POST['coup_use'], "int"),
GetSQLValueString($_POST['VisitorID'], "int"));
mysql_select_db($database_db_name, $db_name);//Make sure you change both to your DB
$Result1 = mysql_query($updateSQL, $db_name) or die(mysql_error());//Make sure you change the $db_name to your DB
$updateGoTo = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
?>
Then under the DOC Type in the <body> is the coupon form:
<form name="form1" action="<?php $_SERVER['PHP_SELF'];?>" method="post">
<input name="coup_use" type="text" value="<?php echo htmlentities($row_rsCoupUpdate['coup_use'], ENT_COMPAT, 'UTF-8'); ?>" size="5" readonly="readonly" /><br />
<input type="submit" value="Use a Coupon" />
<input type="hidden" name="VisitorID" value="<?php echo $row_rsCoupUpdate['VisitorID']; ?>" />
<input type="hidden" name="MM_update" value="form1" />
</form>
At that point you would have a conditional if/else statement that if the # was =<0 a message (in place of the form) would say All Coupons Used or something.
Make sure you change the DB name in the code and set your DB coup_use default value to 3.
This (minus style) should work as written. Let me know.
Best,
Jay