Jump to content

Newbie in need of help


JamesUK91

Recommended Posts

Hi, I realise that this is a newbie question but I only started PHP at college last week.

I need to create a form where the user inputs a month of the year and the form outputs the number of days in that month.

My current code says that there are 31 days in every month..  :confused:

 

Here is what I have for the form, this part is working fine

<form name="months" method="post" action="Task2Algorithm1.php">

Enter Month <input name="month" ><br>

    <button type="submit" style="float:left">Submit</button>

</form>

 

And here is the code for the form, dreamweaver is saying there are no syntax errors but it still isn't working because it says there are 31 days in each month, so I have no idea.

<?php

$month=$_POST['month'];

 

if ($month == "January" OR "March" OR "May" OR "July" OR "August" OR "October" OR "December")

{

echo "The number of days in this month is 31";

}

 

elseif ($month == "April" OR "June" OR "September" OR "November")

{

echo "The number of days in this month is 30";

}

 

elseif ($month == "February")

{

echo "The number of days in this month is 28";

}

?>

 

Any suggestions would be GREATLYYY appreciated :)

 

Link to comment
Share on other sites

You need to do something like:

 

  if ($month == "January" OR $month == "March" ...

 

The way you were doing it was checking if $month == "January" or "March" which gets evaluated to true, so it's always true.

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.