Below is a script that I wrote to allow affiliates to recommend my sit to their friends. In the process of e-mailing it also sends the information to a mySQL db. Everything works great except for the fact that I get a db entry for every input box on the form. I have it so they can e-mail up to 6 friends. If they only put in two I get two e-mails sent put but I get 6 rows inserted to the db.
Any input would be appreciated.
Thanks,
Mel Miller
recommend.php3
<?php
require ("dbheaderxxxxx.php"); #keep db info here
$url = "http://www.hispeedproductions.com/cgi-bin/affiliates/clickthru.cgi?id=$affiliatename";
$subject = "$name wants you to check this site out";
$youremail= "hispeed@hispeedproductions.com";
MYSQL_CONNECT($hostname, $username, $password) or die("unable to connect to server");
@mysql_select_db("$dbname") or die("unable to connect to database");
PRINT "";
PRINT "<body bgcolor=ffffcc>";
PRINT "<center>";
PRINT "Thank You $name, we have received your request recommend HiSpeed Affiliate program.";
PRINT "<br><br>";
PRINT "</center>";
#email to HiSpeed - notification of addition
mail("$youremail",
"database addition",
"Affiliate member, $affiliatename recommended HiSpeed Internet Services"
,"From: $from_email");
to affiliate from you
mail(" $from_email",
"Your recommendation has been sent!",
"Thank you for taking the time to recommend HiSpeed Internet Services.",
"From: $youremail");
for ($i = 0; $i < count($to_email); $i++) {
#e-mail to prospect from affiliate
mail(
"$to_email[$i]",
"$subject",
"Greetings $to_name[$i],
I think you would you should check out $url they have a affiliate program that will pay you and it cost nothing to sign up!",
"From: $from_email");
$query = "INSERT INTO $usertable (name,email,referred_by,affiliate_name) VALUES ('$to_name[$i]','$to_email[$i]','$name','$affiliatename')";
$result = MYSQL_QUERY($query);
}
MYSQL_CLOSE()
?>