<?php

	include "library.php";

	$cxn = start_code();

    $email_address = val( $_POST, "email_address" );
    
    
    if ($email_address != "")
    {
        $query = "SELECT * FROM profile WHERE email = '".$email_address."'";
        
		$result = run_query( $query, $cxn );
		
        $num_found = query_num_rows( $result );
        

            // safety check
            
		if ($num_found > 20)
		{
            echo "More than 20 profiles with this email address, not updated.<br><br>";
		}
		else
		if ($num_found == 0)
		{
            echo "No profiles found with this email address.<br><br>";
		}
		else
		{
            $query = "UPDATE profile SET returned_mail = 'yes', email_address_valid = 'no' WHERE email = '".$email_address."'";
            
		    $result = run_query( $query, $cxn );            
		    
		    $count = $cxn->affected_rows;
		    
            echo "Database updated, ".$num_found." records found, ".$count." records updated<br><br>";
		}
    }
    else
            echo "Email address blank.<br><br>";

?>    
	