Reputation: 101
I am trying to redirect the page dependent on whether a counter is the same as the size of an array. However the IF
statement is ignoring its arguments and operating anyway. my code is;
<?php
session_start();
include 'connection.php';
include 'DayOffDateTest.php';
$usernameid = $_POST['usernameid'] ;
$reason = $_POST['reason'];
$countme = 0;
$size = sizeof($dayOfTheWeek) - 1;
$size2 = sizeof($dayOfTheWeek);
for ($count = 0; $count <= $size; $count++) {
$query = "SELECT title FROM daysoff WHERE date = '$dateMonthYearArr[$count]' AND reason <> ''";
$result = mysql_query($query);
$unavailable_users = array();
while($request = mysql_fetch_array($result)) {
$unavailable_users[] = $request["title"];
}
if(count($unavailable_users) < 3){
$countme = $countme + 1;
$query = "INSERT INTO daysoff (`title`, `date`,`reason`) VALUES ('$usernameid', '$dateMonthYearArr[$count]', '$reason')";
$toomany = array();
$dayoff = mysql_query($query);}
else {
$toomany[] = "There are to many users booked off for ". $dateMonthYearArr[$count] .", please speak to your manager.</br><hr width=100%>";
}
} $_SESSION['many'] = $toomany;
if($countme = $size2){
header('Location: '. $_SERVER['HTTP_REFERER']) ;
}
else{
header('Location: ../toomany.php') ;
}
?>
It is the last IF
statement, whose arguments are $counter
and $size2
, that is not working. I have echoed out the values and everything is as expected.
Upvotes: 1
Views: 59
Reputation: 68526
The
if($countme = $size2){
should be
if($countme == $size2){
You are doing an assignment instead of comparison !
Sidenote : This(mysql_*
) extension is deprecated as of PHP 5.5.0
, and will be removed in the future. Instead, the MySQLi
or PDO_MySQL
extension should be used. Switching to PreparedStatements
is even more better to ward off SQL Injection attacks !
Upvotes: 1