What the heck is wrong with this?

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
p3
-


Joined: 17 Jun 2005
Posts: 615

PostPosted: Wed Jul 27, 2005 10:40 pm    Post subject: What the heck is wrong with this? Reply with quote

I'm having problems with a PHP script I wrote....

Please, no comments on how bad it is (if it is)...

Anyways, here is the PHP ONLY Part of the Page

Code:

<?php
$today= date("l");
if
$today="Monday";
{
echo "Hey! Today's Monday! The work week is just beginning! (To bad for you!)";
}
elseif
$today="Tuesday";
{
echo "Today is Tuesday! Only four more days left in the work week!";
}
elseif
$today="Wednesday";
{
echo "Today's Wednesday! You're already halfway to the weekend!";
}
elseif
$today="Thursday";
{
echo "Today's Thursday! The weekend is just around the corner!";
}
elseif
$today="Friday";
{
echo "Yeah! Today is Friday! The weekend is <i>almost</i> here!";
}
elseif
$today="Saturday";
{
echo "The weekend is here! The weekend is here!";
}
elseif
$today="Sunday";
{
echo "Enjoy the last day of your weekend!";
}
else
{
echo "Hmm... Unless another day of the week was suddenly added, something is wrong with my PHP script....";
}
echo "<br><br><br>";
?>


Or, here is the whole page...
Code:

<html>
<head>
</head>
<body>
<body bgcolor="beige">
<?php
$today= date("l");
if
$today="Monday";
{
echo "Hey! Today's Monday! The work week is just beginning! (To bad for you!)";
}
elseif
$today="Tuesday";
{
echo "Today is Tuesday! Only four more days left in the work week!";
}
elseif
$today="Wednesday";
{
echo "Today's Wednesday! You're already halfway to the weekend!";
}
elseif
$today="Thursday";
{
echo "Today's Thursday! The weekend is just around the corner!";
}
elseif
$today="Friday";
{
echo "Yeah! Today is Friday! The weekend is <i>almost</i> here!";
}
elseif
$today="Saturday";
{
echo "The weekend is here! The weekend is here!";
}
elseif
$today="Sunday";
{
echo "Enjoy the last day of your weekend!";
}
else
{
echo "Hmm... Unless another day of the week was suddenly added, something is wrong with my PHP script....";
}
echo "<br><br><br>";
?>


Hi!<br><br>
This is a preview of things to come... I'll let you know when the page is all ready!!! You can click back to return to the page with links to my other site designs... this site will replace those when it is done... they will, however, remain on my server, so you can view the old pages!

</body>
</html>


I've tried debuggers... they don't help.

The log says it expects a "(" on line 9...

Any help would be much appreciated!!!
Back to top View user's profile Send private message Send e-mail
Anonymoose
-


Joined: 09 Sep 2003
Posts: 2192

PostPosted: Wed Jul 27, 2005 11:15 pm    Post subject: Reply with quote

None of the lines with if statements should end with a ;

Horrible programming. Use a switch instead of a huge chain of elseif's. If you're a competent programmer in any other language (especially C) you should know this.

http://www.w3schools.com/php/php_conditionals.asp for an example of a switch statement and to see how your if/else structure should have been written.

If you repeat it using the proper method and still have problems, post again.
_________________

"Invent an idiot proof webserver and they'll invent a better idiot..."
Back to top View user's profile Send private message
p3
-


Joined: 17 Jun 2005
Posts: 615

PostPosted: Wed Jul 27, 2005 11:28 pm    Post subject: Reply with quote

OK, thanks Anonymoose!

I'm currently reading a book on how to clean up PHP Coding, maybe that'll help...
Back to top View user's profile Send private message Send e-mail
p3
-


Joined: 17 Jun 2005
Posts: 615

PostPosted: Wed Jul 27, 2005 11:33 pm    Post subject: Reply with quote

Anonymoose wrote:
None of the lines with if statements should end with a ;

Horrible programming. Use a switch instead of a huge chain of elseif's. If you're a competent programmer in any other language (especially C) you should know this.

http://www.w3schools.com/php/php_conditionals.asp for an example of a switch statement and to see how your if/else structure should have been written.

If you repeat it using the proper method and still have problems, post again.

Nope, still not working...

Here is the code with the changes:

Code:

<html>
<head>
</head>
<body>
<body bgcolor="beige">
<html>
<head>
</head>
<body>
<body bgcolor="beige">
<?php
$today= date("l");
if
$today="Monday"
{
echo "Hey! Today's Monday! The work week is just beginning! (To bad for you!)"
}
elseif
$today="Tuesday"
{
echo "Today is Tuesday! Only four more days left in the work week!"
}
elseif
$today="Wednesday"
{
echo "Today's Wednesday! You're already halfway to the weekend!"
}
elseif
$today="Thursday"
{
echo "Today's Thursday! The weekend is just around the corner!"
}
elseif
$today="Friday"
{
echo "Yeah! Today is Friday! The weekend is <i>almost</i> here!"
}
elseif
$today="Saturday"
{
echo "The weekend is here! The weekend is here!"
}
elseif
$today="Sunday"
{
echo "Enjoy the last day of your weekend!"
}
else
{
echo "Hmm... Unless another day of the week was suddenly added, something is wrong with my PHP script...."
}
echo "<br><br><br>";
?>


Hi!<br><br>
This is a preview of things to come... I'll let you know when the page is all ready!!! You can click back to return to the page with links to my other site designs... this site will replace those when it is done... they will, however, remain on my server, so you can view the old pages!

</body>
</html>

Hi!<br><br>
This is a preview of things to come... I'll let you know when the page is all ready!!! You can click back to return to the page with links to my other site designs... this site will replace those when it is done... they will, however, remain on my server, so you can view the old pages!

</body>
</html>


and here is the error log entry:
[quote="PHP Erro Log]
[27-Jul-2005 15:31:12] PHP Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in C:\Program Files\Abyss Web Server\htdocs\underconstruction\content.php on line 14
[/quote]
Back to top View user's profile Send private message Send e-mail
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Wed Jul 27, 2005 11:39 pm    Post subject: Reply with quote

Since your comparing the different days of the week , you should use the equal
operator which is == , also be sure to wrap every elseif into parenthesis. I hope
this helps your coding , here's a short example of my piece of code.

Code:

<?php
$today = date("l");

if ($today=="Monday") {
  echo "Hello, World! Its Monday!";
}
?>


Last edited by TRUSTAbyss on Wed Jul 27, 2005 11:51 pm; edited 4 times in total
Back to top View user's profile Send private message Visit poster's website
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Wed Jul 27, 2005 11:40 pm    Post subject: Reply with quote

P3, your PHP-skills sucks.
Basic ELSEIF-syntax:

elseif (valute) {
blablabla
}

Learn the basic! Get some skills and UTFG!


Last edited by cmxflash on Thu Jul 28, 2005 12:10 am; edited 3 times in total
Back to top View user's profile Send private message
p3
-


Joined: 17 Jun 2005
Posts: 615

PostPosted: Wed Jul 27, 2005 11:46 pm    Post subject: Reply with quote

New code, as per that article... its still not workin':
Code:
<html>
<?php
$today= date("l");
switch ($today)
{
Monday:
echo "Hey! Today's Monday! The work week is just beginning! (To bad for you!)"
break;
Tuesday:
echo "Today is Tuesday! Only four more days left in the work week!"
break;
Wednesday:
echo "Today's Wednesday! You're already halfway to the weekend!"
break;
Thursday:
echo "Today's Thursday! The weekend is just around the corner!"
break;
Friday:
echo "Yeah! Today is Friday! The weekend is <i>almost</i> here!"
break;
Saturday:
echo "The weekend is here! The weekend is here!"
break;
Sunday:
echo "Enjoy the last day of your weekend!"
break;
default:
echo "Hmm... Unless another day of the week was suddenly added, something is wrong with my PHP script...."
break;
}
echo "<br><br><br>";
?>


Back to top View user's profile Send private message Send e-mail
p3
-


Joined: 17 Jun 2005
Posts: 615

PostPosted: Wed Jul 27, 2005 11:47 pm    Post subject: Reply with quote

TRUSTpunk wrote:
Since your comparing the different days of the week. You should use the equal
operator which is == , also be sure to wrap every elseif into parenthesis. Hope
this helps your coding , here's a short example of my piece of code.

Code:

<?php
$today = date("l");

if ($today=="Monday") {
  echo "Hello, World! Its Monday!";
}
?>

Thanks!
Back to top View user's profile Send private message Send e-mail
p3
-


Joined: 17 Jun 2005
Posts: 615

PostPosted: Thu Jul 28, 2005 12:21 am    Post subject: Reply with quote

Oh, and thanks Anonymoose for the useful link!
Back to top View user's profile Send private message Send e-mail
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Thu Jul 28, 2005 11:20 am    Post subject: Reply with quote

p3, have you ever heard of or used the 'edit' button?
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
p3
-


Joined: 17 Jun 2005
Posts: 615

PostPosted: Thu Jul 28, 2005 2:29 pm    Post subject: Reply with quote

The Inquisitor wrote:
p3, have you ever heard of or used the 'edit' button?

Yes, I have Andy.
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group