Hey everyone,
I'm having an undefined variable error where I have marked in red. The variables i and f2 are defined in another method somewhere else in the code. Please tell me how to fix these errors. Thanks in advance!!

function showDateBox()
{
    $startDate = array();
    $endDate = array();
    $dayarray = array();
    $day=date("N");

    if($day==7) 
    {
        $startDate[0] = $day;
        $endDate[0] = date('Y-m-d',strtotime('next Saturday'));
        echo ($startDate[0]." to ".$endDate[0]."<br>");
    }
    else 
    {
        $startDate[0] = date('Y-m-d',strtotime('previous Sunday'));
        $endDate[0] = date('Y-m-d',strtotime('next Saturday'));
        //echo ($startDate[0]." to ".$endDate[0]."<br>");
    }

    for($w=1;$w<=5;$w++)
    {
    $startDate[$w] = date('Y-m-d',strtotime('next Sunday'.$w.' week'));
    $endDate[$w] = date('Y-m-d',strtotime('next Saturday'.($w+1).' week'));
    //echo ($startDate[$w]." to ".$endDate[$w]."<br>");
    }

    echo '<form action="shiftConfirm.php" method="get" name="dateSubmissionForm">';
    echo '<select name="startWeek" onchange="submitDate()">';

    for($w=0; $w<sizeof($startDate); $w++)
    {
        if(isset($_GET['startWeek']))
        {
            if($_GET['startWeek']==$w)
            {
                $selectedString = "selected = selected";
            }
            else
            {
                $selectedString = "";
            }
        }
        else
        {
            $selectedString = "";
        }
        echo '<option value="'.$w.'"'.$selectedString.'>'.$startDate[$w]." to ".$endDate[$w]. '</option>';
                $day1 = date("Y-m-d", strtotime("+0 day", $startDate[$w]));
                $day2 = date("Y-m-d", strtotime("+1 day", $startDate[$w]));
                $day3 = date("Y-m-d", strtotime("+2 day", $startDate[$w]));
                $day4 = date("Y-m-d", strtotime("+3 day", $startDate[$w]));
                $day5 = date("Y-m-d", strtotime("+4 day", $startDate[$w]));
                $day6 = date("Y-m-d", strtotime("+5 day", $startDate[$w]));
                $day7 = date("Y-m-d", strtotime("+6 day", $startDate[$w]));
                $dayarray = array($day1, $day2, $day3, $day4, $day5, $day6, $day7);
    }
    echo '</select>';
    echo '</form>';
}
//this function will go through the days for each individual shift name and if they are within the specified day period, it will add the information to an array to use for later.
function goThroughDays()
{
$valuearray = array();
$locationarray = array();
$ps = 0;
$u = 0;
 if($fortitle == 0)
 {
            $u = 0; 
            $ps = 0; 
                for($l = 0; $l<=6; $l++)
                    {
                    if($dayarray[$l] == [COLOR="red"]$f2[/COLOR])
                        {
                         $valuearray[$u]= [COLOR="red"]$f2[/COLOR]; 
                         $locationarray[$ps]=[COLOR="red"]$i[/COLOR]; 
                         $ps++;
                         $u++;
                        }
                    }  
}
                for($l = 0; $l<=6; $l++)
                    {
                    if([COLOR="Red"]$dayarray[/COLOR][$l] == [COLOR="red"]$f2[/COLOR])
                        {
                            $valuearray[$u]= [COLOR="red"]$f2[/COLOR]; 
                            $locationarray[$ps]=[COLOR="red"]$i[/COLOR]; 
                            $ps++;
                            $u++;
                        }
                    }   
}

Are your variables defined above this code or below? Sometimes I forgot to place certain variables above the rest of the code and it works.

L.

variables i and f2 are defined below. dayarray is in the method directly above (as you can see in my pasted code).

It sounds like all you need to do is move the defined variables i and f2 at the top.

L.

Nope, that didn't work.

Have you tried to pass the variables to your function?

// somewhere you are calling this function, presumably with $i and $f2 already set.
function goThroughDays() {
...
}
// so change your function call and pass your variables into it.
function goThroughDays($i,$f2) {
// then $i and $f2 are available to your function.
...
}
// after $i and $f2 are set then call your function.
// wherever you are calling that function in your code was not included 
// with the original question.
//so change
goThroughDays(); 
//to
goThroughDays($i,$f2);

Dear DDYMACEK,

Thanks! I figured out how to fix it just before I read your answer, but yours is right. Thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.