Page 1 of 1

no html o/p

Posted: Mon Aug 10, 2009 2:47 pm
by lipun4u
Why the following code does not give any html o/p ???

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Script7</title>
</head>
 
<body>
    <?php
        if( 1+2 == 3) 
            print "this is true<br>";
        $a = "yes";
        if($a == "yes") {
            print "$a is equal to yes<br>";
            $a="no";
        }
        $a=1;
        $b=6;
        $c="y";
        if(($a==$b)||($b+$a==7 && &c=="y") || 1) {
            print "example 3 is true<br>";
        }
        if($a=$b) {
            print "example 4 is true<br>";
        }
        if($a==$b) {
            print "example 5 is true<br>";
        }
    ?>
</body>
</html>
 

Re: no html o/p

Posted: Mon Aug 10, 2009 3:10 pm
by robnet
Hi lipun4u,
It looks like a parse error: check line 20:

Code: Select all

 
if(($a==$b)||($b+$a==7 && &c=="y") || 1) {
 
I think you meant to type $c rather than &c. - It runs fine after changing it

Re: no html o/p

Posted: Mon Aug 10, 2009 3:16 pm
by lipun4u
thanx

Re: no html o/p

Posted: Mon Aug 10, 2009 3:19 pm
by robnet
No worries - perhaps I hit send too soon though :oops:
It's worth turning error reporting on for dev work. These typos will happen whatever your skill level of php is, and error reporting can save hours of frustration and hundreds of kick-yourself moments! (Turn it off for live systems though!)

http://uk3.php.net/manual/en/errorfunc. ... -reporting

If you have access to php.ini add these lines:

Code: Select all

 
error_reporting  =  E_ALL
display_errors = On
 
Or if you don't have, you can add these lines to your php:

Code: Select all

 
error_reporting(E_ALL | E_STRICT);
ini_set("display_errors", 1);
 
This would have shown you the error:

Code: Select all

 
Parse error: syntax error, unexpected '&' in /path/to/file.php on line 20
 

Re: no html o/p

Posted: Mon Aug 10, 2009 4:28 pm
by lipun4u
Thank you robnet. It helped me a lot..