search

Home  >  Q&A  >  body text

There will be an error message when entering for the first time, and it will disappear when you click the button.

<meta charset="utf8">
<p>Normal year and leap year calculator</p>
<form>
<input type="text" name= "num1">
<input type="submit" value="Judgment">
</form>]PS2RRFF5669X7~3S7N}XRR.pngCU}AW~B7NU4HAI$ZL_H%M5R.png

<?php
$num1=$_GET['num1'];
if(!is_numeric($num1))
{echo 'Please enter the year correctly';
exit;}
if($num1%4 ==0 and $num1 0!==0 or $num1@0==0)
{echo $num1.

红红火火恍恍惚惚红红火火恍恍惚惚1947 days ago1397

reply all(7)I'll reply

  • 海风

    海风2019-10-09 11:09:14

    $_GET['num1'] does not exist when you first enter. It will be an error to assign a non-existent value to a variable, so give $num1 an initial value, such as: $num1 = isset($_GET[' num1']) ? $_GET['num1'] : 2019;

    If you don't want the sentence "2019 is a normal year" to appear as soon as you refresh, modify the program as follows:

    <?php

    if (!empty($_GET['num1'])){

    $num1=$_GET['num1'];

    if(!i

    reply
    1
  • 红红火火恍恍惚惚

    Okay, thank you, boss.

    红红火火恍恍惚惚 · 2019-10-09 22:41:12
    红红火火恍恍惚惚

    Why does isset report an error and empty does not?

    红红火火恍恍惚惚 · 2019-10-09 23:07:47
    红红火火恍恍惚惚

    Boss, I just tried it and the conclusion is that when num1 is not empty, execute $num1=$_GET['num1']; If num1 is empty, the code within the curly brackets will not be executed. Is my conclusion correct or wrong?

    红红火火恍恍惚惚 · 2019-10-09 23:17:50
    海风

    Check the manual. The empty function determines whether the parameter is empty. If the parameter is empty, the empty function returns true. Therefore, if num1 is empty, empty('num1') returns true, !empty('num1') returns false, so the code within the curly brackets will not be executed.

    海风 · 2019-10-10 09:22:57
  • 卢小强

    卢小强2019-10-08 11:52:19

    You can print out the value of $num1 when entering for the first time. I guess it is NULL. NULL cannot be used as an operation.

    reply
    1
  • 红红火火恍恍惚惚

    It is indeed null. How to solve this problem?

    红红火火恍恍惚惚 · 2019-10-08 20:13:50
  • Cancelreply