View Full Version : <body> not loading when there's if statement

01-14-2010, 11:52 AM
Is there any way to make this work?

function theOnload(){
echo "<body style=\"background-color: #515151;\"";
if($_GET["works"] == "home" or $_GET["works"] == ""){
echo " onLoad=\"myLatestWorks();\"";
echo " >\n";

The onLoad shouLd load a popup div tag on the home page. If I block:

function theOnload(){
echo "<body style=\"background-color: #515151;\"";
/*if($_GET["works"] == "home" or $_GET["works"] == ""){
echo " onLoad=\"myLatestWorks();\"";
echo " >\n";
The page loads if not it shows blank.

01-14-2010, 01:25 PM
function theOnLoad() {
echo '<body style="background-color: #515151"'.
((!isset($_GET['works']) || $_GET['works'] == 'home' || $_GET['works'] == '') ? ' onload="myLatestWorks();">' : '>');
}Try that

01-14-2010, 01:26 PM
With PHP, "or" is ||

if($_GET["works"] == "home" || $_GET["works"] == ""){

You're getting a blank screen because PHP failed and you don't have
error reporting turned-on. Turn on PHP error reporting via your PHP config
with your webhost control panel or using .htaccess

01-14-2010, 01:32 PM
That wouldn't throw an error. It's perfectly logical to have OR written there. They both work

01-14-2010, 01:35 PM
global $_GET;

Is required within the function I'm pretty sure.

01-14-2010, 01:37 PM
$_GET is a global, so it's not needed. Same as $_POST, $REQUEST, $_SESSION and $_COOKIE

01-14-2010, 01:38 PM
Uh indeed. :)

01-14-2010, 01:51 PM
Could you post a link to your page? :)

01-14-2010, 02:21 PM
I wonder if maybe the variable "works" does not exist with the $_GET.
Would that cause a PHP "warning" ... and because the error reporting is
not enabled, it is throwing a blank screen? So, he needs to suppress warnings,
and turn-on error message to see what's happening?

01-14-2010, 02:22 PM
At best it would cause an undefined index NOTICE, but yeah that might be enough to throw it