无法让简单的PHP工作; 简单的elseif图像切换器按计划进行

I can't seem to figure out what the problem is here. I'm hosted on GoDaddy, and I wrote a basic .htaccess file so the website would be password protected since it's for a client. I can't find anything wrong with the php code itself but I'm new to php so I may be missing something obvious. Here's the code:

<?php
$date = date("m,d");

if($date == "10,06"){ 
     echo("<img src="maps/img1.jpg" />");
}
elseif($date == "10,10" or "10,11" or "10,12" or "10,13"){
     echo("<img src="maps/img2.jpg" />");
}
elseif($date == "10,18" or "10,19" or "10,20"){
     echo("<img src="maps/img3.jpg" />");
}
elseif($date == "10,25" or "10,26" or "10,27"){
     echo("<img src="maps/img4.jpg" />");
}
elseif($date == "11,01" or "11,02" or "11,03"){
     echo("<img src="maps/img5.jpg" />");
}
elseif($date == "11,07"){
     echo("<img src="img6.jpg" />");
}
elseif($date == "11,22" or "11,23" or "11,24"){
     echo("<img src="maps/img7.jpg" />");
}
elseif($date == "12,01"){
     echo("<img src="maps/img8.jpg" />");
}
elseif($date == "12,06" or "12,07" or "12,08"){
     echo("<img src="maps/img9.jpg" />");
}
else{
     echo("<img src="maps/img10.jpg" />"); 
}
?>

I'm coding in dreamweaver and the code appears 'dead,' but I can't figure out what is wrong with it. The problem seems to be on this line:

if($date == "10,06"){ echo("<img src="maps/img1.jpg" />");
}

But I don't see anything wrong with it. If I put it in the body of an HTML file, I get the images showing up with a mess of code all around them. If I put it in a .php file, I get this error message:

Parse error: syntax error, unexpected T_STRING in /home/content/##/blahblah/html/test.php on line 12

If this is any clue, I've tried running a simple

<?php echo "hello world"; ?>

And it simply comes up blank. So I have a feeling it's a permissions error, but I haven't the faintest how to fix it. I tried adding this string into the .htaccess file

AddType application/x-httpd-php .html

which only results in an internal server error.

Right now the ONLY thing the .htaccess file has in it is this:

AuthUserFile /home/content/##/blahblah/html/.htpasswd
AuthGroupFile /dev/null
AuthName "EnterPassword"
AuthType Basic

require valid-user

(and of course I have the .htpasswd file in the root as well)

So I probably need to put more stuff into .htaccess but I have no idea what.


EDIT: I fixed the echo and else statement errors (thanks!!), and I tested it on both a .html and a .php. Now it seems the problem is the server doesn't want to read the php in the html file, because it seems to work fine on the .php test. As I mentioned before, I tried adding the AddType application/x-httpd-php .html string into the .htaccess file, but it just messes up the whole website. I'll go to the test.html and it will ask me if I want to download the page after I put that string in.

EDIT2: I seem to have solved the embedding php problem. After a large amount of research, I discovered that GoDaddy allows you to apply custom extensions like so:

Options +ExecCGI
AddHandler x-httpd-php5-3 .mysite

through which I would replace '.mysite' with '.html'

Works like a dream now. (though I have yet to see if this causes other problems in the future)

Thanks to all for correcting my statements---definitely would never have worked without that!

Every echo function you coded is wrong. Each of them should be like below :

echo "<img src='maps/img1.jpg' />";

Here is the manual page of echo : php.net/manual/en/function.echo.php

if($date == "10,06"){ echo("<img src=\"maps/img1.jpg\" />");

You need to escape your quotes by backslashing those inside double quotes, else the PHP interpreter recognizes this as the end of your echo statement, which it then expects to end entirely or to concatenate. Or as mentioned below use a combination of single and double quotes to avoid the problem entirely.

Check more here: http://www.tizag.com/phpT/echo.php

To use quotes inside a string you must to scape them if is the same type of quote that you used to start the string. If you are using single quotes it is good to use double quotes on it like in $str = 'this "was" something'; But if you are using double quotes you have to scape them to tell the parser that you are not finishing the string at that point: $str = "this \"was\" something";. So the parser understand that the quote is an actual character, not the end of the string.

The same applies if you are using single quoted string: $str = 'this \'was\' something';.

Here you can get more information about PHP strings:

To specify a literal single quote, escape it with a backslash (). To specify a literal backslash, double it (\). All other instances of backslash will be treated as a literal backslash: this means that the other escape sequences you might be used to, such as or , will be output literally as specified rather than having any special meaning.

escape double quotes in your strings

echo "<img src=\"maps/img1.jpg\" />"

or use single quotes

echo "<img src='maps/img1.jpg' />"

Ok, there's a lot to go at here, I'm not sure if these will resolve your problems but from the example provided this needs changing.

Your echo statements need changing to single quotes:

if($date == "10,06"){ 
 echo("<img src='maps/img1.jpg' />"); //Note use of single quotes
}

Or you can escape them with slashes:

if($date == "10,06"){ 
 echo("<img src=\"maps/img1.jpg\" />"); //Note use of escaping
}

Your elseif statements need changing

elseif($date == "10,10" or $date == "10,11" or $date == "10,12" or $date == "10,13"){
 echo("<img src='maps/img2.jpg' />"); // You are missing this      ^------^
}

You can also drop the parentheses on the echo:

if($date == "10,06"){ 
 echo "<img src='maps/img1.jpg' />"; //Note lack of parentheses
}

As for the .htaccess does it work properly without it?

Your echo statements are not using proper double quotes.

So, your statement:

echo("<img src="maps/img1.jpg" />");

Is closing at "maps and hence code coming after it is apparently a Parse Error.

Corrected one:

echo("<img src=\"maps/img1.jpg\" />");

You should always have a good practice to close your strings properly.

This makes you sure that you do not get any Parse Error/Warning or undesired output.