View previous topic :: View next topic |
Author |
Message |
p3 -
Joined: 17 Jun 2005 Posts: 615
|
Posted: Wed Jul 27, 2005 10:40 pm Post subject: What the heck is wrong with this? |
|
|
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 |
|
 |
Anonymoose -
Joined: 09 Sep 2003 Posts: 2192
|
Posted: Wed Jul 27, 2005 11:15 pm Post subject: |
|
|
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 |
|
 |
p3 -
Joined: 17 Jun 2005 Posts: 615
|
Posted: Wed Jul 27, 2005 11:28 pm Post subject: |
|
|
OK, thanks Anonymoose!
I'm currently reading a book on how to clean up PHP Coding, maybe that'll help... |
|
Back to top |
|
 |
p3 -
Joined: 17 Jun 2005 Posts: 615
|
Posted: Wed Jul 27, 2005 11:33 pm Post subject: |
|
|
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 |
|
 |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Wed Jul 27, 2005 11:39 pm Post subject: |
|
|
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 |
|
 |
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Wed Jul 27, 2005 11:40 pm Post subject: |
|
|
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 |
|
 |
p3 -
Joined: 17 Jun 2005 Posts: 615
|
Posted: Wed Jul 27, 2005 11:46 pm Post subject: |
|
|
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 |
|
 |
p3 -
Joined: 17 Jun 2005 Posts: 615
|
Posted: Wed Jul 27, 2005 11:47 pm Post subject: |
|
|
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 |
|
 |
p3 -
Joined: 17 Jun 2005 Posts: 615
|
Posted: Thu Jul 28, 2005 12:21 am Post subject: |
|
|
Oh, and thanks Anonymoose for the useful link! |
|
Back to top |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Thu Jul 28, 2005 11:20 am Post subject: |
|
|
p3, have you ever heard of or used the 'edit' button? _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
p3 -
Joined: 17 Jun 2005 Posts: 615
|
Posted: Thu Jul 28, 2005 2:29 pm Post subject: |
|
|
The Inquisitor wrote: | p3, have you ever heard of or used the 'edit' button? |
Yes, I have Andy. |
|
Back to top |
|
 |
|