Form Voucher Generator

Hello,
I am working on getting what I think is a fairly simple script put together…The basic functions I want are:
Free Voucher/Coupon generated and sent on email submission
A way to cancel the coupon and keep it from being printed over and over again
Set a time limit/counter for the offer link to expire once it’s clicked on.

What I am trying to do is put a simple form on my site to collect and store an email address for my opt-in list:

[code]




[/code]

Once the visitor enters their email, it will redirect them to a PHP generated image voucher with a random voucher number on it(or if it’s possible, I create the voucher image and just have it stamped with a random code):

Random code generator code:
[php]
// assuming MySQL table with (id, code, effect)
mysql_query( “insert into coupons set effect=’”.$effect."’");
// “effect” will be some keyword to identify what the coupon does
$id = mysql_insert_id();
$code = $id.“F”;
$codelen = 32; // change as needed
for( $i=strlen($code); $i<$codelen; $i++) {
$code .= dechex(rand(0,15));
}
mysql_query( “update coupons set code=’”.$code."’ where id=".$id);

// now, when you are given a code to redeem, say $_POST[‘code’]
list($code,$effect) = mysql_fetch_row( mysql_query( “select code, effect from coupons where id=’”.((int) $_POST[‘code’])."’"));
if( $code != $_POST[‘code’]) die(“Code not valid”);
else {
// do something based on $effect
}
[/php]

Image with code on it code:
[php]<?
header (“Content-type: image/png”);

$img_handle = ImageCreate (400, 300) or die (“Cannot Create image”);
$back_color = ImageColorAllocate ($img_handle, 0, 10, 10);
$txt_color = ImageColorAllocate ($img_handle, 235, 235, 51);
ImageString ($img_handle, 10, 25, 5, “Hello world!”, $txt_color);
ImagePng ($img_handle);
// assuming MySQL table with (id, code, effect)
mysql_query( “insert into coupons set effect=’”.$effect."’");
// “effect” will be some keyword to identify what the coupon does
$id = mysql_insert_id();
$code = $id.“F”;
$codelen = 32; // change as needed
for( $i=strlen($code); $i<$codelen; $i++) {
$code .= dechex(rand(0,15));
}
mysql_query( “update coupons set code=’”.$code."’ where id=".$id);

// now, when you are given a code to redeem, say $_POST[‘code’]
list($code,$effect) = mysql_fetch_row( mysql_query( “select code, effect from coupons where id=’”.((int) $_POST[‘code’])."’"));
if( $code != $_POST[‘code’]) die(“Code not valid”);
else {
// do something based on $effect
}
?>
[/php]

[php][/php]

I can’t figure how to tie the functions I want into one so that it works… Any help with this would be much appreciated.

Thank you…

did you accidently added an extra php block qoute?

Yes. Sorry about that.

Anyone care to guide me with this?

i will take a look in moment

I sent you a private message

your index page just send me to an error page

Sponsor our Newsletter | Privacy Policy | Terms of Service