JamesUK91 Posted August 18, 2011 Share Posted August 18, 2011 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.. 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 Quote Link to comment https://forums.phpfreaks.com/topic/245083-newbie-in-need-of-help/ Share on other sites More sharing options...
Alex Posted August 18, 2011 Share Posted August 18, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245083-newbie-in-need-of-help/#findComment-1258881 Share on other sites More sharing options...
WebStyles Posted August 18, 2011 Share Posted August 18, 2011 All you need is date to output the number of days in a given month. example: <?php $month = "february"; echo date("t",strtotime($month)); ?> hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/245083-newbie-in-need-of-help/#findComment-1258882 Share on other sites More sharing options...
JamesUK91 Posted August 18, 2011 Author Share Posted August 18, 2011 Ahhhhh thanks so much guys you're lifesavers Quote Link to comment https://forums.phpfreaks.com/topic/245083-newbie-in-need-of-help/#findComment-1258885 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.