what i am attempting to build is an array from a database query in php mysql. loop through that array looking for a certain string with strpos.
when the register page loads, i include a file, this file source is below:
mysql_select_db($database_connBlog, $connBlog);
$query_rsBannedDomains = "SELECT * FROM banned_emailproviders";
$rsBannedDomains = mysql_query($query_rsBannedDomains, $connBlog) or die(mysql_error());
$row_rsBannedDomains = mysql_fetch_assoc($rsBannedDomains);
$totalRows_rsBannedDomains = mysql_num_rows($rsBannedDomains);
$bannedArray = array();
do {
array_push($bannedArray, $row_rsBannedDomains['domain_emailprovider']);
}
while ($row_rsBannedDomains = mysql_fetch_assoc($rsBannedDomains));
//print_r($bannedArray);
$emailaddress = $_POST['email_usr'];
foreach($bannedArray as $key => $domain){
if(strpos($emailaddress, $domain) == false){
echo (strpos($emailaddress, $domain));
} else {
header ("Location: http://www.disney.com");
}
}
When the register page is submitted, it is submitted to itself. The include to the source above, is the second line in the register php file. the first line is the include for the database connection.
The odd thing is this works sometimes when I click back and re submit the form.
You don’t need to load the whole table and then loop through it with PHP. In fact this is a very inefficient way of doing it. Just query the database to see if the domain part of the email address is one of the entries in the table instead.
Please note the above code hasn’t been tested so it might need some tweaking to work properly.