techguy388 Posted January 9, 2011 Share Posted January 9, 2011 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 More sharing options...
ignace Posted January 9, 2011 Share Posted January 9, 2011 list(,$domain) = explode('@', $email); Link to comment https://forums.phpfreaks.com/topic/223879-searching-in-a-mysql-database/#findComment-1157114 Share on other sites More sharing options...
techguy388 Posted January 9, 2011 Author Share Posted January 9, 2011 Thanks for the reply! Where would I put this line? Link to comment https://forums.phpfreaks.com/topic/223879-searching-in-a-mysql-database/#findComment-1157131 Share on other sites More sharing options...
ignace Posted January 9, 2011 Share Posted January 9, 2011 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"; Link to comment https://forums.phpfreaks.com/topic/223879-searching-in-a-mysql-database/#findComment-1157139 Share on other sites More sharing options...
techguy388 Posted January 9, 2011 Author Share Posted January 9, 2011 Thanks Ignace! It works perfectly. I do have a question though. Suppose a user's email address is "[email protected](etc..).alloweddomain.com" How could I get the database to recognize this as a match? Thanks again! Link to comment https://forums.phpfreaks.com/topic/223879-searching-in-a-mysql-database/#findComment-1157148 Share on other sites More sharing options...
BrendanmPHP Posted January 10, 2011 Share Posted January 10, 2011 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 } ?> Link to comment https://forums.phpfreaks.com/topic/223879-searching-in-a-mysql-database/#findComment-1157617 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.