PHP & SQLSERVER Bit field validation

Hi Experts,
I have developed a PHP script that must compare the day of the week (real time date day of week) with a range of bit fields in a SQLSRV database.
The fields in question in the DB (names of the fields) are the days of the week
i.e.
Monday bit
Tuesday bit
etc
with values set by another program to True or False depending of visitor been allowed or not
The script works to some extent with the script actually picking up the correct day of week and setting the variable ($Allowtoday) in question.
However, I think that the loop does not actually exit when it should and the  value is set back again to 'no' when the condition has actually, correctly set it to 'yes'
The objective is that if condition is met and the switch sets $Allowtoday to 'yes' that the code:
if($Allowtoday = 'no') {
      echo $Allowtoday;
      echo "<div style ='font:60px/80px Arial,tahoma,sans-serif;color:#ff0000;text-align:center'> Person not Authorised </div><br>";
      echo "<div style ='font:60px/80px Arial,tahoma,sans-serif;color:#ff0000;text-align:center'> to Enter Premises Today! </div><br>";
      exit;
}
Is not executed

See full code extract  below
$sql = "SELECT * FROM DayVisitor WHERE Username = (?)";
$params = array(&$_REQUEST['Name']);
$stmt = sqlsrv_query( $conn, $sql, $params );
if( $stmt === false) {
    echo "Your details was not found. Please try again or Register <br />";
	die( print_r( sqlsrv_errors(), true) );
	}
$Allowtoday = 'no';
$timestamp = time();
$whatdayisit = date('D', $timestamp);
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {

switch ($whatdayisit) {

    case "Mon";
        if($row['Monday'] === true){
            $cellno = $row['AuthorisedCellNo'];
			$Allowtoday = 'yes';
            break;
        }
        else
        {
            //echo '<dd><strong>Person not Authorised to Enter on a Monday! </strong></dt> ';
           
        }
    case "Tue";
        if($row['Tuesday'] === true){
            $cellno = $row['AuthorisedCellNo'];
			$Allowtoday = 'yes';
            break;
        }
        else
        {
            //echo '<dd><strong>Person not Authorised to Enter on a Tuesday! </strong></dt> ';
           
        }
    case "Wed";
        if($row['Wednesday'] === true){
            $cellno = $row['AuthorisedCellNo'];
			$Allowtoday = 'yes';
            break;
        }
        else
        {
            //echo '<dd><strong>Person not Authorised to Enter on a Wednesday! </strong></dt> ';
          
        }
    case "Thu";
        if($row['Thursday'] === true){
            $cellno = $row['AuthorisedCellNo'];
			$Allowtoday = 'yes';
            break;
        }
        else
        {
            //echo '<dd><strong>Person not Authorised to Enter on a Thursday! </strong></dt> ';
           
        }
    case "Fri";
        if($row['Friday'] === true){
            $cellno = $row['AuthorisedCellNo'];
			$Allowtoday = 'yes';
            break;
        }
        else
        {
           // echo '<dd><strong>Person not Authorised to Enter on a Friday! </strong></dt> ';
           
        }
    case "Sat";
        if($row['Saturday'] === true){
            $cellno = $row['AuthorisedCellNo'];
			$Allowtoday = 'yes';
            break;
        }
        else
        {
           // echo '<dd><strong>Person not Authorised to Enter on a Saturday! </strong></dt> ';

           
        }
    case "Sun";
	
	    if($row['Sunday'] === true){
			$cellno = $row['AuthorisedCellNo'];
			$Allowtoday = 'yes';
		    break;
        }
        else
        {
           // echo '<dd><strong>Person not Authorised to Enter on a Sunday! </strong></dt> ';
           
        }
		
}
	
}

if($Allowtoday = 'no') {
	echo $Allowtoday;
	echo "<div style ='font:60px/80px Arial,tahoma,sans-serif;color:#ff0000;text-align:center'> Person not Authorised </div><br>";
	echo "<div style ='font:60px/80px Arial,tahoma,sans-serif;color:#ff0000;text-align:center'> to Enter Premises Today! </div><br>";
	exit;
}

Open in new window

Zack SnydersAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
if($Allowtoday = 'no') { is an assignment because it has a single '=' sign which makes $Allowtoday Always equal to 'no'.  For a comparison, it should be if($Allowtoday == 'no') { .
Ray PaseurCommented:
TL;DR and I think Dave has found the error, but I would like to offer a design suggestion.  Make this more human-friendly by storing the values in clear text.  You will need to write much less code (and therefore many fewer unit tests) to prove correctness in the application.
Ray PaseurCommented:
Some theory here:
http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html

Simplified example here:
http://iconoun.com/demo/temp_foo.php
<?php // demo/temp_foo.php
error_reporting(E_ALL);

$row =
[ 'Monday'    => TRUE
, 'Tuesday'   => TRUE
, 'Wednesday' => TRUE
, 'Thursday'  => TRUE
, 'Friday'    => TRUE
, 'Saturday'  => TRUE
, 'Sunday'    => FALSE
]
;

$tests = [ 'Monday', 'Wednesday', 'Sunday', 'Thursday' ];

// TEST THE DAYS
echo '<pre>';
foreach ($tests as $day)
{
    if ($row[$day])
    {
        echo PHP_EOL . "$day Allowed";
    }
    else
    {
        echo PHP_EOL . "$day ***** Not Allowed";
    }
}

Open in new window

Best regards, ~Ray

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Zack SnydersAuthor Commented:
Thank you for this.
Dave has correctly identified an error.
The problem is however that at the time of  the comparison, the value of  $allowtoday has somehow changed back to 'no'
I identified this by a test  just before the (incorrect) comparison as indicated by Dave.
Fixing my problem was now achieved by improving the design (example and the link by Ray)
Thanks
Rgs
Ray PaseurCommented:
Thanks for the points.  This is actually a perfect place to use the ternary operator, since we are testing for true or false.  Makes for more compact and easy-to-understand code.
<?php // demo/temp_foo.php
error_reporting(E_ALL);

$row =
[ 'Monday'    => TRUE
, 'Tuesday'   => TRUE
, 'Wednesday' => TRUE
, 'Thursday'  => TRUE
, 'Friday'    => TRUE
, 'Saturday'  => TRUE
, 'Sunday'    => FALSE
]
;

$tests = [ 'Monday', 'Wednesday', 'Sunday', 'Thursday' ];

// TEST THE DAYS
echo '<pre>';
foreach ($tests as $day)
{
    $signal = $row[$day] ? 'Allowed' : '*** Not Allowed'; // TERNARY OPERATOR
    echo PHP_EOL . $day . ' ' . $signal;
}

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.