【问题标题】:Isset function in php 5.4.16 is not funcitoningphp 5.4.16 中的 isset 函数不起作用
【发布时间】:2017-12-22 09:58:51
【问题描述】:

php版本下

PHP 5.2.4 (cli) (built: Oct 16 2007 16:54:49)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

isset 函数工作正常,下面是脚本中的 sn-p。

<form name="fff" method=post style="font-size:12pt;">

 <tr height="24">
          <td height="24" width="105"> <p align="left" style="margin-left:10;"><b><font face="Arial"><span style="font-size:10pt;"><?php echo $Agent_03; ?></span></font></b></p> </td>
          <td height="24" width="40">
            <p align="center">
              <input type="text" name="CosHour_03" value="<?php echo $AtdH_03; ?>" style="font-weight:normal; font-size:10pt; color:rgb(102,102,102); text-align:center; on" maxlength="2" size="2">
            </p>
          </td>
          <td height="24" width="5"> <p align="center"><b><font face="Arial"><span style="font-size:10pt;">:</span></font></b></p> </td>
          <td height="24" width="40">
            <p align="center">
              <input type="text" name="CosMine_03" value="<?php echo $AtdM_03; ?>" style="font-weight:normal; font-size:10pt; color:rgb(102,102,102); text-align:center; on" maxlength="2" size="2">
            </p>
          </td>
          <td height="24" width="105">
            <p align="right">
              <input type="text" name="Cs_03" value="" style="font-weight:normal; font-size:10pt; color:rgb(102,102,102); on" maxlength="12" size="12">
            </p>
          </td>
          <td height="24" width="185">
            <p align="left"><input type="text" name="CnsCoe_03" value="<?php echo $CleCoe_03; ?>" style="font-weight:normal; font-size:10pt; color:rgb(102,102,102); on" maxlength="24" size="24">
            </p>
          </td>
        </tr>

<p align="center" ;">
        <input type="submit" name="ReportCons_Submit" value="SUBMIT" style="font-family:Arial; font-weight:bold; font-size:14; color:rgb(32,46,125); letter-spacing:4; text-align:center; background-color:rgb(204,204,204); margin-left:0;" size="200">
      </p>

</form>


<?php

if ( isset( $ReportCons_Submit)) {

          $alertmessage   = "";
          $successmessage = "";
          $strCountry     = strtoupper( $Country);
          $strLocation    = strtoupper( $Location);
          $strFixedDate   = date("Ymd", strtotime(date("Y")."-".$CnsMonth."-".$CnsDay));
.
.
.
.
?>

同样的事情在最近的 php 版本中不起作用。

PHP 5.4.16 (cli) (built: Apr  4 2016 07:13:18)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

如果我们点击提交按钮,我感觉控件不会进入 if 语句。

我们将不胜感激。

【问题讨论】:

  • 您能说明变量 $ReportCons_Submit 的定义位置吗?

标签: php forms submit isset


【解决方案1】:

isset 有效,但 $ReportCons_Submit 不存在。

使用

if (isset($_POST['ReportCons_Submit'])) {...}

“问题”是由register_globals 引起的,它在 PHP 5.4.0 中被删除(在 PHP 5.3.0 中已弃用)。

【讨论】:

  • HI @panther $_POST 工作正常,它进入 if 语句,但变量没有被声明。我收到以下错误。注意:未定义变量:注意:未定义变量:注意:未定义变量:注意:未定义变量:
  • 没有未定义来自表单的变量。 $Country$Location 和其他人也没有定义——不是在 PHP 代码中,也不是在你的表单中。例如,name=CosHour_03 的输入值将在 $_POST['CosHour_03'] 等中。如果 $Location 来自另一个来源(不是来自表单),请检查是否存在。 $Location = isset($Location) ? strtoupper( $Location) : 'default value if isn't defined';
  • 那些是之前在同一个脚本中定义的,我没有在这里生成整个脚本,这个 php 文件将打开文本框和提交按钮,我们将输入一些值,按提交,然后它应该进入 if 语句并将值输入数据库。该过程在早期版本的 PHP 中运行良好,但与我们在新 php 版本框中的目录结构相同,添加 $_POST 函数时会引发错误。
  • @sabarishjackson:什么错误?由于删除了寄存器全局变量,无法通过添加(正确)$_POST['key'] 到 post 变量来导致未定义的变量。
【解决方案2】:

试试if (isset($_POST['ReportCons_Submit'])){}。它应该可以工作。

【讨论】:

    【解决方案3】:

    试试

    if(!empty($ReportCons_Submit)){
    
    }
    

    而不是

    if(isset($ReportCons_Submit)){
    
    
    }
    

    【讨论】:

    • 为什么要这么做?当isset 失败时,为什么!empty 应该起作用?
    • @panther 因为 !empty() 仅当存在 null、false、0 或空字符串以外的值时才会评估为 true,而如果您的变量具有空数据(如空字符串),则 isset 会嘎嘎作响。
    • 但问题不在于null 或其他值。这是关于在 PHP 5.4.0 中删除的全局寄存器。 ReportCons_Submit是提交输入的名称,不能是nullfalse等,其值为SUBMIT
    猜你喜欢
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2013-05-28
    • 2018-10-04
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 2020-09-23
    相关资源
    最近更新 更多