Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Date: Sun, 14 Oct 2012 21:28:49 +0200 From: Luuk User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.php Subject: Re: Verifying time in php References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 56 NNTP-Posting-Host: 2001:980:9089:1:b83f:9443:38bb:36f1 X-Trace: 1350243001 news.xs4all.nl 6862 [2001:980:9089:1:b83f:9443:38bb:36f1]:50964 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.php:7324 On 14-10-2012 11:45, houghi wrote: > I have a form that has the following entry fields: > hours > minutes > seconds > > I need the time in seconds and that works: > $realtime=$_POST['hours']*3600+$_POST['minutes']*60+$_POST['seconds']; > > However people can fill out nothing or they could enter characters > > What is the easiest way to verify if what the people filled out is > correct? I have tried, but I get lost in the if statements. > > Extra difficult is that they must not fill out all three. Only one is > enough. e.g. > 1 hour and no minutes or second gives 3600 > 1 hour, 1 minute and 1 second gives 3661 > 1 hour and 'X' should give an error. > All empty should give an error > empty hour 70 minutes and 75 seconds gives 4275. > Hours of more then 24 will be possible as well. > I might even add number of days. > > If the last one gives an error, but it makes the life much easier, I can > live with that > > It is the fact that they do not need to fill out all three that I am > stuck. > > What I have tried is first to see if all are empty > Next try to see if each one is not a number > Then I need to figure out if there is a combination of some of it. > > And that is when I get lost in the if statements and loops in loops. > > I am sure there is an easy way to tell if all is nice and works well, > but how? Seaching google gave me transfering from seconds to H:i:s, but > that is not what I want. > > houghi > whats wrong with this code: