Jump to content

Searching in a MySQL database


techguy388

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 "[email protected]" as being LIKE "yahoo.com."

 

How can I get my code working in such a way that it recognizes "[email protected]" 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";

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.