【问题标题】:warning: division by zero [closed]警告:除以零[关闭]
【发布时间】:2011-07-29 04:21:58
【问题描述】:

我正在使用以下静态方法发送邮件警报,但它会引发错误:warning:division by zero ...

Postman::MailAlert($_POST['email'],'Hello '.$_POST['name'].', Thanks for signing up.Your customer id is '.$_POST['city']/'/'.$product_id.'.');

我已经通过输入@解决了这个问题,但是为什么会提出这个问题,我做错了什么?

【问题讨论】:

  • PHP.net : Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why. 所以它不能解决问题,它会忽略这个问题。
  • @Wh1T3h4Ck5 感谢您的建议。

标签: php


【解决方案1】:

你应该使用

Postman::MailAlert($_POST['email'],'Hello '.$_POST['name'].', Thanks for signing up.Your customer id is '.$_POST['city'].'/'.$product_id);

【讨论】:

    【解决方案2】:

    只是问题部分:

    $_POST['city']/'/'.$product_id.'.');
    

    需要这样改。

    $_POST['city'] . '/'.$product_id.'.');
    

    【讨论】:

    • 如果解决了您的问题,请勾选我的回答为正确,谢谢。 :)
    • 哦,对了,那是我的错,我想现在可以解决了,谢谢。
    • @seoppc 你能把我的答案标记为正确吗?
    • 这个应用程序要求我等待 5 分钟,然后我将其标记为答案
    • @seoppc 现在请重试 :)
    【解决方案3】:

    $_POST['city']/'/' 应该变成$_POST['city'].'/',快速输入时的常见错误

    【讨论】:

      【解决方案4】:

      接近那行代码的末尾:

      [...]$_POST['city']/'/'[...]
      

      添加一些空格以使其清晰:

      [...] $_POST['city'] / '/' [...]
      

      您试图将$_POST['city'] 除以'/'。如果 PHP 将非数字字符串 ('/') 解释为数值为 0,那么您将除以 0。

      也许你的意思是连接而不是分割?

      【讨论】:

      • 我猜这只是一个错字
      【解决方案5】:

      $_POST['city']/

      顺便说一句——你会清理用户输入吗?我看到您直接使用 $_POST 数组变量 - 不要这样做。用户可能会在此处提交任何内容,甚至是一些讨厌的字符串,您有责任确保这些内容不会损害您的应用程序。

      P.S.:添加 @ 是一种不好的做法,因为它只会抑制错误消息(消除症状),而不是修复原因。 http://php.net/manual/en/language.operators.errorcontrol.php

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多