Jump to content

404 not found error


dwayn

Recommended Posts

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

Link to comment
Share on other sites

<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 :)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.