PDA

View Full Version : check if username exists before inserting again


jay
09-07-2009, 11:49 PM
Hi

I have a simple registration form that feeds the db.

How can I check if the username(email) already exists in the user table before inserting it again.

I am currently look if there are records in the recordset, how do I check for a specific email address. The email address entered in my form?

Here is what I have so far:

// Error Function
function Trigger_CheckEmail(&$tNG) {
$myThrowError = new tNG_ThrowError($tNG);
$myThrowError->setErrorMsg("Your email already exists on our system. You can use the same email and passowrd to login as a Seller, Buyer or Agent");
$myThrowError->setField("email");
$myThrowError->setFieldErrorMsg("Your email already exists on our system. You can use the same email and passowrd to login as a Seller, Buyer or Agent");
return $myThrowError->Execute();


// Create recordset
mysql_select_db($database_prop, $prop);
$query_users = "SELECT email FROM mymembers";
$users = mysql_query($query_users, $prop) or die(mysql_error());
$row_users = mysql_fetch_assoc($users);
$totalRows_users = mysql_num_rows($users);



// Register triggers
$ins_mymembers->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_mymembers->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
$ins_mymembers->registerTrigger("END", "Trigger_Default_Redirect", 99, "login_register_buy_agent.php?email={email}&pass={password}&type={type}");
$ins_mymembers->registerConditionalTrigger("{POST.password} != {POST.re_password}", "BEFORE", "Trigger_CheckPasswords", 50);
$ins_mymembers->registerConditionalTrigger("$totalRows_users > 0", "BEFORE", "Trigger_CheckEmail", 50);
$ins_mymembers->registerTrigger("AFTER", "Trigger_SendEmail", 98);

jay
09-10-2009, 12:51 PM
For those who were wondering this is how i solved the problem.

I made the email(username) field on my DB unique and then echo'ed the sql message.

Jay

domedia
09-11-2009, 01:42 AM
Thanks for providing the solution as well jay, it's appreciated.