Ok, this one has me baffled. I have a page for a video rental home delivery service to allow customers to browse the movies. There's a button to allow switching between VHS and DVD (simply calls a seperate page to change a session variable and return). The code to display the button is part of a display block as follows:
<CODE>
$platsel = $_SESSION[platsel];
if ($platsel < 1) {
$_SESSION[platsel] = 1;
$platsel = 1;
}
if ($platsel == 1) { $platname = "DVD"; $otherplat = "Switch To VHS"; }
if ($platsel == 2) { $platname = "VHS"; $otherplat = "Switch To DVD"; }
$header_block .=" <td align=\"center\"><div style=\"PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 0px\"><font color=990000><input type=\"button\" value=\"$otherplat\" onClick=window.location=\"demoswitchplat.php\"></div></td>\n";
</CODE>
As far as I can tell, all seems happy there. However, the first time the page is called I see a syntax error, and upon looking at the source output to the browser, I see this:
<td align="center"><div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 0px"><font color=990000><input type="button" value="Switch To VHS" onClick="window.location=""demoswitchplat.php"></div></td>
Note the way the quotes around the onClick are messed up. Refreshing the page fixes the problem:
<td align="center"><div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 0px"><font color=990000><input type="button" value="Switch To VHS" onClick=window.location="demoswitchplat.php"></div></td>
I'm assuming this has something to do with the session, but I can't for the life of me figure out why it doesn't work the first time when there is no session variable yet.
<CODE>
$platsel = $_SESSION[platsel];
if ($platsel < 1) {
$_SESSION[platsel] = 1;
$platsel = 1;
}
if ($platsel == 1) { $platname = "DVD"; $otherplat = "Switch To VHS"; }
if ($platsel == 2) { $platname = "VHS"; $otherplat = "Switch To DVD"; }
$header_block .=" <td align=\"center\"><div style=\"PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 0px\"><font color=990000><input type=\"button\" value=\"$otherplat\" onClick=window.location=\"demoswitchplat.php\"></div></td>\n";
</CODE>
As far as I can tell, all seems happy there. However, the first time the page is called I see a syntax error, and upon looking at the source output to the browser, I see this:
<td align="center"><div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 0px"><font color=990000><input type="button" value="Switch To VHS" onClick="window.location=""demoswitchplat.php"></div></td>
Note the way the quotes around the onClick are messed up. Refreshing the page fixes the problem:
<td align="center"><div style="PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; PADDING-TOP: 0px"><font color=990000><input type="button" value="Switch To VHS" onClick=window.location="demoswitchplat.php"></div></td>
I'm assuming this has something to do with the session, but I can't for the life of me figure out why it doesn't work the first time when there is no session variable yet.