by kyle04 » Mon Jul 09, 2012 4:47 pm
You would need a form set up to post the variables to the script , very generally, assuming the customer has to input their data in some form (email address would be the most reliable) :
<form name="button20" method=POST action="this_script.php">
<input type=hidden name="points_value" value="20">
Enter Email : <input type=text name="customer_email" size=15>
<input type=submit name="submit_points" value="Submit">
</form>
<?
foreach($_POST as $name=>$value) {
${$name} = $value;
// echo $name." - ".$value."<br>"; // for testing, commented out here
}
if(isset($_POST['submit_points'])) {
$result = mysql_query("SELECT FROM YOUR_TABLE_NAME WHERE FIELD_EMAIL = '$customer_email'");
$row = mysql_fetch_array($result);
if(!$result) {
echo "No records for ".$customer_email." found";
// error proceedure here
}
$stored_points = $row['FIELD_STORED_POINTS'];
if($points_value>$stored_points) { // not enough stored points for item
echo "The item points value exceeds your current points total";
echo "You currently have ".$stored_points." available";
exit; // or other options here
}
else { // update the table
$new_points_value = $stored_points-$points_value;
$update = mysql_query("UPDATE YOUR_TABLE_NAME SET FIELD_STORED_POINTS = '$new_points_value' WHERE FIELD_EMAIL = '$customer_email'");
// then do the email script here
}
}
?>
AndyP