Jump to content

Comparing entered information to an existing entry.


Dark57

Recommended Posts

So I'm trying to see if an email is already registered before letting someone continue with the registration process to stop multiple accounts being linked to the same email.  I'm not sure how to do this but I was wondering if there is a way to go through the database looking for a specific email?  I'm sure there is I just don't know how to do it.

Well you can check if an email already exists like this (assuming you have a table that stores the email)

 


$targetEmail = '[email protected]'; // or get from $_POST ?

$sql = "SELECT COUNT(*) FROM mytable WHERE email = '$targetEmail'";
$result = mysql_query($sql);

if($result)
{
    if(mysql_num_rows($result) == 1)
    {
        $count = (int)mysql_result($result, 0, 0);
        if($count > 0)
        {
             // email already exists
        }
    }
}

Ok. I think I see what I have to do.

 

$targetemail = $_POST['myemail'];
$sql = "SELECT COUNT(*) FROM $tbl_name WHERE email = '$targetemail' LIMIT";
if (isset(!$sql))
{
//continue registration?
}
else
{
//email error message?
}

 

Is that a rough idea of what I should be doing? And also what does LIMIT do?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.