I’m looking for help adding a coupon code box onto our existing webpage.
All I want to do is add a box that will subtract 10% from the subtotal if they have a valid coupon code. I’m not sure how simple or complex this might be. From looking around it looks like I need a “coupons” file that will have a list of the valid coupon codes and then I need to add the box that they will type in there code for validation. Also I would like to make it so once the code is used it is deemed invalid i.e. coupons can only be used once. Any and all help is appreciated. I’m a newbie with little to no html/php experience. To check out what the code is currently like go to: [url]http://www.oldcities.com
Thanks again
/josh
[code=php]$couponcode = "2940230422"; // Get this value from a textbox somewhere.
$_SESSION['couponcode'] = $couponcode;[/code]
[code=php]$total = "102.30"; //some sum of money
$couponquery = "SELECT * FROM couponcodes
WHERE code
= '".$_SESSION['couponcode']."' LIMIT 1";
if(mysql_num_rows($couponquery) == 1)
{
$totaltopay = ($total * 0.9);
echo "Valid Coupon Code: Deducted 10% from Total.<br />"
$deletecoupon = mysql_query("DELETE FROM couponcodes
WHERE code
= '".$_SESSION['couponcode']."' LIMIT 1") or die(mysql_error());
}
else
{
$totaltopay = $total;
}
// continue with normal procedure...[/code]
couponcode
code
[code=php]
$couponcode = "2940230422"; // Get this value from a textbox somewhere.
$_SESSION['couponcode'] = $couponcode;
$couponcode = "2940230423"; // Get this value from a textbox somewhere.
$_SESSION['couponcode'] = $couponcode;
$couponcode = "2940230424"; // Get this value from a textbox somewhere.
$_SESSION['couponcode'] = $couponcode;
$couponcode = "2940230425"; // Get this value from a textbox somewhere.
$_SESSION['couponcode'] = $couponcode;
[/code]
[code=php]
<?php
//Connect to the Database
$DBHOST = "localhost"; //I'm assuming your database is on the same host, if not put the hostname here. (db23.host.net) etc..
$DBUSER = "USERNAME"; //Database's username
$DBPASS = "PASSWORD"; // database's password
$DB1 = "database_1"; // Database's NAME
$db = mysql_connect("$DBHOST","$DBUSER","$DBPASS");
mysql_select_db("$DB1",$db) or die(mysql_error()); //code which actually lets you connect, or gives a nice error explaining why something failed.
?>[/code]
[code=php]
$couponcode = "2940230422"; // Get this value from a textbox somewhere.
$_SESSION['couponcode'] = $couponcode;
[/code]
[code=php]$couponcode = "2940230422"; // Get this value from a textbox somewhere.
$_SESSION['couponcode'] = $couponcode;
[/code]
[code=php]$_SESSION['couponcode'] = $_POST['couponcode']; // Probably this one.
//OR
$_SESSION['couponcode'] = $_GET['couponcode']; // Might be this one
//OR
$_SESSION['couponcode'] = $_REQUEST['couponcode']; //if your not sure whether the form uses GET or POST, use this one, this should always work.[/code]
','' or
[code=php]
$deletecoupon = mysql_query("DELETE FROM couponcodes
WHERE code
= '".$_SESSION['couponcode']."' LIMIT 1") or die(mysql_error());
[/code]
[code=php]
$sql_result = mysql_query($sql,$connection)
or die ("Couldn't get Cart");
$num_rows = mysql_num_rows($sql_result) or die(mysql_error());
if ($num_rows < 1) {
// echo "You have no Cart";
header("Location:index.php");
}
[/code]
0.1.9 — BETA 5.25