dwayn Posted December 13, 2010 Share Posted December 13, 2010 Hi every1, I am quite a newbie in php so please bear with ma silly questions.. I use IIS 6.0 . I have a php file named try.php . content is as folows <html> <head>......</head> <body>........som html code here... <?php if (flag==0) { some html code } ?> ...some html code </body> </html> when i open the file it says Error Summary HTTP Error 500.0 - Internal Server Error The page cannot be displayed because an internal server error has occurred. Can anybody tell me what am i doing wrong... It happen with me almost every now and then.. Is there some conceptual mistake am doing? Please clarify.. If the same question has been discussed thousand times before, than do direct me to the proper link... Regards, Dwayne Quote Link to comment Share on other sites More sharing options...
radar Posted December 13, 2010 Share Posted December 13, 2010 <html> <head>......</head> <body>........som html code here... <?php if ($flag==0) { ?> some html code <?php } ?> ...some html code </body> </html> If the code you gave is correct minus the HTML in the 2 spots you erased out, your issue lies in 2 places. #1. if (flag == 0) { should be if ($flag == 0) { unless you have define('flag', 0); #2. before you can output html you either need to echo it out (not recommended) or close php then re-open after the html output is done such as in my example above. Hope it helps Quote Link to comment Share on other sites More sharing options...
dwayn Posted December 13, 2010 Author Share Posted December 13, 2010 Hey thanks a lot.. So, this kind of error appears when there is some mistake in php syntax ..eh? Quote Link to comment Share on other sites More sharing options...
dwayn Posted December 13, 2010 Author Share Posted December 13, 2010 Actually what i want is that if flag equals 0 then the form should be like this else if flag equals 1 than form should contain completely different elements... If i do what u just wrote, than that html code betwen two php tags is getting executed no matter what is the value of flag... Any advice? Quote Link to comment Share on other sites More sharing options...
radar Posted December 13, 2010 Share Posted December 13, 2010 It shouldn't do that... When I used to mix my display with my logic I used that technique all the time. It could be that $flag is getting set to 0 somewhere... you might try: if (isset($flag) && $flag == '0' || $flag == '') { ?> html code <?php } else { ?> more html code <?php } ?> doing something like that might work if you want one code block to show if flag=0 and the other is if equals anything else. How are you obtaining the value for $flag? Quote Link to comment Share on other sites More sharing options...
dwayn Posted December 13, 2010 Author Share Posted December 13, 2010 Can you explain your logic please... coz i just don have if else.. i have values of flag upto 10 and tere is different code of display for each flag. what is this isset($flag) and $flag==") .... Quote Link to comment Share on other sites More sharing options...
radar Posted December 13, 2010 Share Posted December 13, 2010 well if you have up to 10 different flags that can be used that is going to be difficult to do.... If I were you what I would do is create 10 php files 1.php, 2.php, 3.php, etc.... then maybe create a default.php in there too.... then to something like if (isset($flag)) { $flag++; include($flag.".php"); } that way it's one if file, that is including HTML code.... and if you go for having a default.php just in case the $flag isnt set if (!isset($flag)) { include('default.php'); } else { $flag++; include($flag.".php"); } reason why i use $flag++ is because since you're using probably $flag = 0 thru $flag = 9 (10 total) you'll always be behind one so in order to load the correct file (in the case of 0 load one at all) we need to jump that number up one... if the $flag++ doesnt work you can also do $flag = $flag + 1; or $flag = ($flag + 1); and it should work the same. my logic above was if there were only two variables like the original post made it sound.. isset($flag) ensures that $flag really does have a variable in it.... $flag == '' is my way of checking for NULL as I've had issues previously where checking for null so I switched to the double quote representation of null. Quote Link to comment Share on other sites More sharing options...
dwayn Posted December 13, 2010 Author Share Posted December 13, 2010 thanks a lot... Quote Link to comment Share on other sites More sharing options...
MMDE Posted December 13, 2010 Share Posted December 13, 2010 Do you want 404 error or 500 error? For such errors you should send header messages... header('HTTP/1.1 404 Not Found'); or header('HTTP/1.1 500 Internal Server Error'); also should be noted that headers should be sent before anything else. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.