简体   繁体   English

我的 IF 条件不起作用,直接跳入 ELSE 语句

[英]My IF condition is not working and is directly jumping into the ELSE statement

I want to check whether the current time is past 12p.m and pass and execute the codes indie the IF statement but it is directly going into the Else statement.我想检查当前时间是否超过 12p.m 并通过并执行独立于 IF 语句的代码,但它直接进入 Else 语句。 I think the condition is not right.我认为条件不对。 May I know the right way of finding out whether the current time has past the specific time that I've given?我可以知道找出当前时间是否已经超过我给出的特定时间的正确方法吗?

My codes我的代码

<?php

                if (date('H') > 12){

                    $myDate = date('m/d/Y');

                    include_once '../classes/config.php';

                    $con = mysqli_connect(HOST, USER, PASS, DB) or die('Connection Error! '.mysqli_error($con));

                    $checkuser = mysqli_query($con, "SELECT * FROM patient_diary WHERE patient_id = '$id' AND date = '$myDate'") or die(mysqli_error($con));
                    $result = mysqli_num_rows($checkuser);
                   
                    if ($result){?>
                        <div class="head">
                            <div class="title">INSERT STATUS</div>
                        </div>
                        <form action="" method="POST">
                            <div class="insert-details">
                                <div class="input-value">
                                    <small>Condition</small>
                                    <select name="condition" class="conditionscale" required>
                                        <option value="" selected hidden>Select status</option>
                                        <option value="much better">Much Better</option>
                                        <option value="better">Better</option>
                                        <option value="same">Same</option>
                                        <option value="worse">Worse</option>
                                        <option value="much worse">Much Worse</option>
                                    </select>
                                </div>
                                <div class="input-value">
                                    <small>Food</small>
                                    <textarea type="text" name="role" placeholder="What did you have?" required></textarea>
                                </div>
                                <div class="input-value">
                                    <small>Date</small>
                                    <input type="text" id="date" name="date" placeholder="MM-DD-YYYY" onfocus="(this.type='date')" onblur="(this.type='text')" required>
                                </div>
                            </div>
                            <div class="insert-elements">
                                <input id="reset" type="reset" name="reset"  class="reset-btn" value="Reset">
                                <input type="submit" name="submitInsert" class="insert-btn" value="Enter" id="insertbtn">
                            </div>
                    <?php } else{ ?>
                        <div class="no-head">
                            <div class="title">You can enter your status details only once a day.</div>
                        </div>
                    <?php } 
                } else{ ?>
                    <div class="no-head">
                        <div class="title">You are allowed to enter your status everyday after 6 p.m only</div>
                    </div>
                <?php
                }
            ?>

My timezone was not properly set inside the php.ini file.我的时区没有在 php.ini 文件中正确设置。 But even without making any changes over there I used the below code to get the right current hour I'm in by declaring my region and city.但即使没有在那里进行任何更改,我也使用以下代码通过声明我的地区和城市来获得正确的当前时间。

  date_default_timezone_set('Region/City');

You can also refer to this link of lists to find what you exactly have to type to get the right time for the place you want.您还可以参考此列表链接以查找您确切必须键入的内容,以便在合适的时间到达您想要的地点。

如果在比较日期时使用“strtotime”,问题就会消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM