Page 1 of 1

New to PHP. Help please

Posted: Tue Feb 17, 2009 1:31 pm
by David S
I'm new to PHP and looking for help, please.

Can anyone tell me why the code below doesn't work? The form is saved as html and the php as weekend.php. I've uploaded to a server but all i get is Have a nice day, whatever is entered into the form.

<form action="weekend.php" method="post">
Date: <input type="text" name="date"><br>
<input type="submit" value="Submit">
</form>

<?php

$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
Thanks!

Re: New to PHP. Help please

Posted: Tue Feb 17, 2009 2:19 pm
by LanceEh
I'm rusty with my PHP and I'm trying to get back into it, but I think you need to assign the posted "date" variable to something. The $d=date("D"); looks wrong.

Re: New to PHP. Help please

Posted: Tue Feb 17, 2009 2:39 pm
by LanceEh
The date function will always output what the server has. So if the server says it is Friday then date('D') will output 'Fri'. You can't change this.

Re: New to PHP. Help please

Posted: Tue Feb 17, 2009 2:44 pm
by LanceEh
Try this and you will see what I mean,

Code: Select all

 
<?php
$d=date("D");
echo "Today is $d";
?>
 
Take care.