I am writing an affiliate program using PHP and mySQL. I have the signup page and the preview page before anything is inserted into the database. What I would like to do is have the script check to see if the affiliate username and email already exists in the database, and display different messages if either one exists.
This is what my preview page looks like now:
<?
require "db.php";
# connect to database
mysql_connect($host,$usr,$pwd);
mysql_select_db ($database);
$query="SELECT * FROM affiliates WHERE aff = '$aff'";
$result = mysql_query($query) or die(mysql_error());
//if the user exists
if (mysql_num_rows($result)>0) {
echo("That username has already been selected; please choose another.<br><br>");
echo("<table width='75%' border='0' cellspacing='1' cellpadding='0'>
<tr>
<td>First Name</td>
<td>$firstname</td>
</tr>
<tr>
<td>Last Name</td>
<td>$lastname</td>
</tr>
<tr>
<td>Email/Paypal ID</td>
<td>$email</td>
</tr>
<tr>
<td>Street Address</td>
<td>$street</td>
</tr>
<tr>
<td>City</td>
<td>$city</td>
</tr>
<tr>
<td>State</td>
<td>$state</td>
</tr>
<tr>
<td>Zip</td>
<td>$zip</td>
</tr>
<tr>
<td>Website</td>
<td>$website</td>
</tr><form name='join' action='preview.php' method='post'>
<tr>
<td><font color='red'>Affiliate ID</font></td>
<td><input type='text' name='aff'></td>
</tr>
<tr>
<td> </td>
<td>
<input type='hidden' name='firstname' value='$firstname'>
<input type='hidden' name='lastname' value='$lastname'>
<input type='hidden' name='email' value='$email'>
<input type='hidden' name='street' value='$street'>
<input type='hidden' name='city' value='$city'>
<input type='hidden' name='state' value='$state'>
<input type='hidden' name='zip' value='$zip'>
<input type='hidden' name='website' value='$website'>
<input type='submit' name='Submit' value='Preview >>'></form>
</td>
</tr>
</table>");
}
?>
<?
$query2="SELECT * FROM affiliates WHERE email = '$email'";
$result2 = mysql_query($query2) or die(mysql_error());
//if the user exists
if (mysql_num_rows($result2)>0) {
echo("<br>You have already signed up for our program; please <a href='login.php'>Click Here</a> to login<br>");
} else {
echo "Please review your input below. If everything looks correct, press Join to submit
your information and join our affiliate program. If you need to make any corrections
press "Back" on your browser.<br>
<br>
<table width='75%' border='0' cellspacing='1' cellpadding='0'>
<tr>
<td>First Name</td>
<td><? echo $firstname; ?></td>
</tr>
<tr>
<td>Last Name</td>
<td><? echo $lastname; ?></td>
</tr>
<tr>
<td>Email/Paypal ID</td>
<td><? echo $email; ?></td>
</tr>
<tr>
<td>Street Address</td>
<td><? echo $street; ?></td>
</tr>
<tr>
<td>City</td>
<td><? echo $city; ?></td>
</tr>
<tr>
<td>State</td>
<td><? echo $state; ?></td>
</tr>
<tr>
<td>Zip</td>
<td><? echo $zip; ?></td>
</tr>
<tr>
<td>Website</td>
<td><? echo $website; ?></td>
</tr>
<tr>
<td>Affiliate ID</td>
<td><?php echo $aff ?> </td>
</tr>
<tr>
<td> </td>
<td><form name='join' action='join.php' method='post'>
<input type='hidden' name='firstname' value='<? echo $firstname; ?>'>
<input type='hidden' name='lastname' value='<? echo $lastname; ?>'>
<input type='hidden' name='email' value='<? echo $email; ?>'>
<input type='hidden' name='street' value='<? echo $street; ?>'>
<input type='hidden' name='city' value='<? echo $city; ?>'>
<input type='hidden' name='state' value='<? echo $state; ?>'>
<input type='hidden' name='zip' value='<? echo $zip; ?>'>
<input type='hidden' name='website' value='<? echo $website; ?>'>
<input type='hidden' name='aff' value='<? echo $aff ?>'>
<input type='submit' name='Submit' value='Join >>'></form>
</td>
</tr>
</table>";
} ?>
You can also try it out here: http://affiliates.heavenly-web.com/signup.php. The problem I am having is while it displays the correct output if the email address exists in the db, when the username exists it displays the proper form and what is supposed to display only when neither the email nor the affiliate id is found. I know it has to be something very simple, but I just cannot figure it out.
Any help would be appreciated.
Thanks!
😃