Paramater value not being passed into a fun ction properly
Posted: Tue Jan 28, 2014 12:11 pm
I have this code that calls a function displayEditSiteNote(...)
$_SESSION["SelectedSiteNoteListNum"] is passed into the function as the last parameter.
Here is the resulting debug output from the echo's, showing a correct value of 3, before and after the function call.
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
Dynamically generated form.
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3################# => echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
Here is the contents of function displayEditSiteNote(...)
Here is the results of the debug echo statements showing that the value 3 outside the function has been turned into an empty string in the last parameter.
WHY FOR FRICK SAKES?
**********0*************
***********************
**********0*************
***********************
***********************
***********************
*********************** => echo "**********".$SelSiteNoteNum."*************<br>"; $SelSiteNoteNum is supposed to contain the value of $_SESSION["SelectedSiteNoteListNum"] which is 3
$_SESSION["SelectedSiteNoteListNum"] is passed into the function as the last parameter.
Here is the resulting debug output from the echo's, showing a correct value of 3, before and after the function call.
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
Dynamically generated form.
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3#################
##################3################# => echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
Code: Select all
else if ($_SESSION["LoginValid"] && (strlen($_SESSION["SaveChanges"]) > 0))
{
//echo "BBBBBBBBBB<br>";
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
doEditThisSiteNote($_SESSION["Shortkey"], getSiteDesc($_POST["SiteName"]), $_POST["Date"], $_POST["Employee"], $_POST["WorkCompleted"], $_POST["WorkToDo"], $_POST["LastEditedBy"], $_POST["LastEditedOn"]);
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
displayEditSiteNote($_SESSION["SiteName"], $_SESSION["ByEmployee"], $_SESSION["Employee"], $_SESSION["ByDate"], $_SESSION["StartDate"], $_SESSION["EndDate"], $_SESSION["SiteNoteListItemNum"]);
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
echo "##################".$_SESSION["SelectedSiteNoteListNum"]."#################<br>";
}
Here is the results of the debug echo statements showing that the value 3 outside the function has been turned into an empty string in the last parameter.
WHY FOR FRICK SAKES?
**********0*************
***********************
**********0*************
***********************
***********************
***********************
*********************** => echo "**********".$SelSiteNoteNum."*************<br>"; $SelSiteNoteNum is supposed to contain the value of $_SESSION["SelectedSiteNoteListNum"] which is 3
Code: Select all
function displayEditSiteNote($SiteName, $ByEmployee, $Employee, $ByDate, $StartDate, $EndDate, $SelSiteNoteNum)
{
$Work = "";
echo "**********".$SiteName."*************<br>";
echo "**********".$ByEmployee."*************<br>";
echo "**********".$Employee."*************<br>";
echo "**********".$ByDate."*************<br>";
echo "**********".$StartDate."*************<br>";
echo "**********".$EndDate."*************<br>";
echo "**********".$SelSiteNoteNum."*************<br>";
echo "<form method=\"POST\" action=\"SiteInfo.php\" name=\"EditSiteNote\">";
echo "<p><input type=\"submit\" value=\"Go back\" name=\"Back\"></p>";
echo "<p> </p>".$_SESSION["DBOpMsg"]."<p> </p>";
echo "<fieldset style=\"padding: 2\">";
echo "<legend>Display site notes</legend>";
echo " <p><label for=\"SiteName\"> Site name </label>";
echo "<select size=\"1\" name=\"SiteName\" id=\"SiteName\">";
displaySiteList($SiteName);
echo "</select></p>";
echo "<p> <input type=\"checkbox\"";
if (isChecked($ByEmployee))
echo " checked ";
else
echo " ";
echo "onclick=\"enableEmployee()\" name=\"ByEmployee\" value=\"ON\" id=\"ByEmployee\">";
echo "<label for=\"ByEmployee\">By employee</label></p>";
echo "<p><label for=\"Employee\"> </label>";
echo "<select size=\"1\"";
if (!isChecked($ByEmployee))
echo " disabled=\"disabled\" ";
else
echo " ";
echo "name=\"Employee\" id=\"Employee\">";
displayEmployeeList($Employee);
echo "</select> </p>";
echo "<p> <input type=\"checkbox\"";
if (isChecked($ByDate))
echo " checked ";
else
echo " ";
echo "name=\"ByDate\" onclick=\"enableDates()\" value=\"ON\" id=\"ByDate\"><label for=\"ByDate\">";
echo "ByDate</label></p>";
echo "<p><label for=\"StartDate\"> Start date ";
echo "</label><input type=\"text\"";
if (!isChecked($ByDate))
echo " disabled=\"disabled\" ";
else
echo " ";
echo "value=\"".$StartDate."\" name=\"StartDate\" size=\"20\" id=\"StartDate\"></p>";
echo "<p><label for=\"EndDate\"> End date ";
echo "</label><input type=\"text\"";
if (!isChecked($ByDate))
echo " disabled=\"disabled\" ";
else
echo " ";
echo "value=\"".$EndDate."\" name=\"EndDate\" size=\"20\" id=\"EndDate\"></p>";
echo "<p> Site notes to edit";
for ($I = 0; $I < 45; $I++)
echo " ";
echo "</p>";
echo " <input type=\"submit\" value=\"Update list\" name=\"EditSiteNote\">";
echo "<p> <select size=\"10\" onchange=\"displayWork()\" name=\"SiteNotesList\" id=\"SiteNotesList\">";
fillSiteNoteListBox($SelSiteNoteNum);
echo "</select><p> Work completed / to do</p> ";
echo "<textarea rows=\"10\" name=\"Work\" cols=\"180\" ";
$Work = getSiteNoteListWork($_SESSION["SitesNoteListItems"][$SelSiteNoteNum]);
echo "id=\"Work\" readonly=\"readonly\">".$Work."</textarea>";
echo "<p> <input type=\"submit\" value=\"Edit this site note\" name=\"EditThisSiteNote\">";
echo " ";
echo " <input type=\"submit\" value=\"Delete this site note\" name=\"DeleteThisSiteNote\"></p>";
echo "</fieldset><p> </p>";
echo "<p> </p>";
echo "<p> </p>";
echo "<p> </p>";
echo "<p> </p>";
echo "</form>";
echo "<script>\r";
echo "\r";
echo "function displayWork()\r";
echo "{\r";
echo " var SiteNoteList = document.getElementById(\"SiteNotesList\");\r";
echo " var Work = document.getElementById(\"Work\");\r";
echo "\r";
echo " switch(SiteNoteList.value)\r";
echo " {\r";
fillSiteNoteListJavascriptFunction($_SESSION[$SiteNoteList][$SelSiteNoteNum]);
echo " }\r";
echo "}\r";
echo "</script>\r";
}