IF语句忽略参数

时间:2014-03-15 19:26:15

标签: php if-statement arguments

我试图根据计数器是否与数组的大小相同来重定向页面。但是IF语句忽略了它的参数并且无论如何都在运行。我的代码是;

<?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') ;
}
?>

这是最后一个IF语句,其参数为$counter$size2,但无效。我已经回应了价值观,一切都如预期的那样。

1 个答案:

答案 0 :(得分:1)

if($countme = $size2){

应该是

if($countme == $size2){

你正在做作业而不是比较!


旁注:此mysql_*)扩展程序自PHP 5.5.0起不推荐使用,将来也会被删除。相反,应使用MySQLiPDO_MySQL扩展名。切换到PreparedStatements甚至可以更好地抵御SQL注入攻击!