N
Nik Saprano
Вообщем народ, есть следующий код:
<?
if(isset($_GET['aff_id'])){
setcookie("aff_id", (int)$_GET['aff_id'], time()+60*60*24*25 ,"/");
$aff_id=$_GET['aff_id'];
}
if(isset($_COOKIE["aff_id"])){
$aff_id=$_COOKIE['aff_id'];
}
session_start();
include "affconfig.php";
include "lang/$language";
include "countries.php";
$errorMsg = '';
if($_POST['commited'] == 'yes')
{
// form was sent
mysql_connect($server, $db_user, $db_pass)
or die ("Database CONNECT Error (line 8)");
if($_POST['ausername'] == '')
$errorMsg .= AFF_SI_UNAMEMISSING.'<br>';
// check if user doesnt exist already
$userid = preg_replace('/[^a-zA-Z0-9_]/', '', $_POST['ausername']); // protect against sql injection
$chk_user = mysql_db_query($database, "select refid from affiliates where refid='$userid'");
if(mysql_num_rows($chk_user) > 0)
{
$errorMsg .= AFF_SI_USEREXISTS.'<br>';
$_POST['ausername'] = '';
}
if($_POST['afirstname'] == '')
$errorMsg .= AFF_SI_FNAME.'<br>';
if($_POST['awebsite'] == '')
$errorMsg .= AFF_SI_WEBSITE.'<br>';
if($_POST['aemail'] == '')
$errorMsg .= AFF_SI_EMAILMISSING.'<br>';
if($_POST['apassword'] == '')
$errorMsg .= AFF_SI_PWDMISSING.'<br>';
if($_POST['apassword2'] == '')
$errorMsg .= AFF_SI_PWDMISSING2.'<br>';
if($_POST['apassword'] == $_POST['apassword2']){}
else
{ $errorMsg .= AFF_SI_PWDMISSING3.'<br>';}
if($errorMsg == '')
{
// save and send notification email
$aemailbody = "Dear ".$_POST['afirstname'].",\n\nThank you for signing up to our affiliate program.\nYour account details are below:\n\n"
."Username: ".$_POST['ausername']."\nPassword: ".$_POST['apassword']."\n\n"
."You can log into your account and view your 'real-time' statistics by going to:\n"
."http://".$domain."\n\n"
."Thank you once again, and we wish you luck with your profit making!\n\n\n"
."Affiliate Manager\n"
.$_POST['emailinfo']."\n\n\n\n";
// mysql_db_query($database, "INSERT INTO affiliates VALUES ('','".$_POST['ausername']."', '".$_POST['apassword']."', '".$_POST['aff_id']."', '".$_POST['acompany']."', '".$_POST['atitle']."', '".$_POST['afirstname']."', '".$_POST['alastname']."', '".$_POST['awebsite']."', '".$_POST['aemail']."', '".$_POST['apayable']."', '".$_POST['astreet']."', '".$_POST['atown']."', '".$_POST['acounty']."', '".$_POST['apostcode']."', '".$_POST['acountry']."', '".$_POST['aphone']."', '".$_POST['afax']."', '".$_POST['adate']."',NOW())")
mysql_db_query($database, "INSERT INTO affiliates VALUES ('','".$_POST['ausername']."', '".$_POST['apassword']."', '".$_POST['aff_id']."', '".$_POST['acompany']."', '".$_POST['atitle']."', '".$_POST['afirstname']."', '".$_POST['alastname']."', '".$_POST['awebsite']."', '".$_POST['aemail']."', '".$_POST['apayable']."', '".$_POST['astreet']."', '".$_POST['atown']."', '".$_POST['acounty']."', '".$_POST['apostcode']."', '".$_POST['acountry']."', '".$_POST['aphone']."', '".$_POST['afax']."',NOW())")
or die(mysql_error());
// $query = "select * from affiliates where refid='".$_POST['ausername']."'";
// $result = mysql_db_query($database, $query);
// $id = mysql_fetch_array($result);
// mysql_db_query($database, "INSERT INTO partners (id,site,number,name,password) VALUES ('','".$_POST['awebsite']."', $id[id], '".$_POST['ausername']."', '".$_POST['apassword']."')")
// or die(mysql_error());
include "thankyou.php";
mail($_POST['aemail'], "Welcome New Affiliate!", $aemailbody, "From:".$emailinfo."\nReply-To:".$emailinfo."\n");
exit;
}
}
?>
Нужно чтобы при регистрации проверялся имэйл на уникальность. Т.е. если такой в базе есть, то выдавать ошибку, если нет - все ок.
Как это сделать?
<?
if(isset($_GET['aff_id'])){
setcookie("aff_id", (int)$_GET['aff_id'], time()+60*60*24*25 ,"/");
$aff_id=$_GET['aff_id'];
}
if(isset($_COOKIE["aff_id"])){
$aff_id=$_COOKIE['aff_id'];
}
session_start();
include "affconfig.php";
include "lang/$language";
include "countries.php";
$errorMsg = '';
if($_POST['commited'] == 'yes')
{
// form was sent
mysql_connect($server, $db_user, $db_pass)
or die ("Database CONNECT Error (line 8)");
if($_POST['ausername'] == '')
$errorMsg .= AFF_SI_UNAMEMISSING.'<br>';
// check if user doesnt exist already
$userid = preg_replace('/[^a-zA-Z0-9_]/', '', $_POST['ausername']); // protect against sql injection
$chk_user = mysql_db_query($database, "select refid from affiliates where refid='$userid'");
if(mysql_num_rows($chk_user) > 0)
{
$errorMsg .= AFF_SI_USEREXISTS.'<br>';
$_POST['ausername'] = '';
}
if($_POST['afirstname'] == '')
$errorMsg .= AFF_SI_FNAME.'<br>';
if($_POST['awebsite'] == '')
$errorMsg .= AFF_SI_WEBSITE.'<br>';
if($_POST['aemail'] == '')
$errorMsg .= AFF_SI_EMAILMISSING.'<br>';
if($_POST['apassword'] == '')
$errorMsg .= AFF_SI_PWDMISSING.'<br>';
if($_POST['apassword2'] == '')
$errorMsg .= AFF_SI_PWDMISSING2.'<br>';
if($_POST['apassword'] == $_POST['apassword2']){}
else
{ $errorMsg .= AFF_SI_PWDMISSING3.'<br>';}
if($errorMsg == '')
{
// save and send notification email
$aemailbody = "Dear ".$_POST['afirstname'].",\n\nThank you for signing up to our affiliate program.\nYour account details are below:\n\n"
."Username: ".$_POST['ausername']."\nPassword: ".$_POST['apassword']."\n\n"
."You can log into your account and view your 'real-time' statistics by going to:\n"
."http://".$domain."\n\n"
."Thank you once again, and we wish you luck with your profit making!\n\n\n"
."Affiliate Manager\n"
.$_POST['emailinfo']."\n\n\n\n";
// mysql_db_query($database, "INSERT INTO affiliates VALUES ('','".$_POST['ausername']."', '".$_POST['apassword']."', '".$_POST['aff_id']."', '".$_POST['acompany']."', '".$_POST['atitle']."', '".$_POST['afirstname']."', '".$_POST['alastname']."', '".$_POST['awebsite']."', '".$_POST['aemail']."', '".$_POST['apayable']."', '".$_POST['astreet']."', '".$_POST['atown']."', '".$_POST['acounty']."', '".$_POST['apostcode']."', '".$_POST['acountry']."', '".$_POST['aphone']."', '".$_POST['afax']."', '".$_POST['adate']."',NOW())")
mysql_db_query($database, "INSERT INTO affiliates VALUES ('','".$_POST['ausername']."', '".$_POST['apassword']."', '".$_POST['aff_id']."', '".$_POST['acompany']."', '".$_POST['atitle']."', '".$_POST['afirstname']."', '".$_POST['alastname']."', '".$_POST['awebsite']."', '".$_POST['aemail']."', '".$_POST['apayable']."', '".$_POST['astreet']."', '".$_POST['atown']."', '".$_POST['acounty']."', '".$_POST['apostcode']."', '".$_POST['acountry']."', '".$_POST['aphone']."', '".$_POST['afax']."',NOW())")
or die(mysql_error());
// $query = "select * from affiliates where refid='".$_POST['ausername']."'";
// $result = mysql_db_query($database, $query);
// $id = mysql_fetch_array($result);
// mysql_db_query($database, "INSERT INTO partners (id,site,number,name,password) VALUES ('','".$_POST['awebsite']."', $id[id], '".$_POST['ausername']."', '".$_POST['apassword']."')")
// or die(mysql_error());
include "thankyou.php";
mail($_POST['aemail'], "Welcome New Affiliate!", $aemailbody, "From:".$emailinfo."\nReply-To:".$emailinfo."\n");
exit;
}
}
?>
Нужно чтобы при регистрации проверялся имэйл на уникальность. Т.е. если такой в базе есть, то выдавать ошибку, если нет - все ок.
Как это сделать?