Jump to content

Recommended Posts

I have setup a page in php that allows users to register for access to a website.  One of the fields on my form allows the user to enter an email address, and I want to compare what they enter with data in a table in a MySQL database.  I want to restrict registration based upon the domain of the email address that the user enters.  Here's the code I'm using now:

 

$domainsearch = mysql_query("SELECT domains FROM allowedDomains WHERE domains LIKE '$email'");
$returnedrows = mysql_num_rows($domainsearch);
if ($returnedrows<=0 ){
$err=$err."You must enter an acceptable email address";

 

Example of 'domains' data in database:

'yahoo.com'

'gmail.com'

 

This code only works if I enter "yahoo.com" or "gmail.com" in the form.  It doesn't recognize "username@yahoo.com" as being LIKE "yahoo.com."

 

How can I get my code working in such a way that it recognizes "username@yahoo.com" as being related to the "yahoo.com" row in my database?

 

Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/223879-searching-in-a-mysql-database/
Share on other sites

list(,$domain) = explode('@', $email);
$domain = mysql_real_escape_string($domain);
$domainsearch = mysql_query("SELECT domains FROM allowedDomains WHERE domains LIKE '$domain'");
$returnedrows = mysql_num_rows($domainsearch);
if ($returnedrows<=0 ){
$err=$err."You must enter an acceptable email address";

You already have

<?php
if ($returnedrows<=0 ){
$err=$err."You must enter an acceptable email address";
?>

So if it does match you would do

 

<?php
if ($returnedrows<=0 ){
$err=$err."You must enter an acceptable email address";
}else{
//match
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.