【问题标题】:I can't find what's wrong with my PHP code. Can anyone see an error? [duplicate]我找不到我的 PHP 代码有什么问题。任何人都可以看到错误吗? [复制]
【发布时间】:2018-10-23 21:36:46
【问题描述】:

我已经检查了我的代码一千次,但它从来没有正确弹出,所以我尝试了一个 PHP Checker/Tester。它告诉我在 /home4/phptest/public_html/code.php70(5) 中调用未定义函数 test_input() :eval()'d code:4 Stack trace: #0 /home4/phptest/public_html/code.php70(5 ): eval() #1 {main} throw on line number 4 这是什么意思?请帮忙!

<?php

        ($_SERVER["REQUEST_METHOD"] == "GET");
        $charName = test_input($_GET["charName"]);
        $charType = test_input($_GET["charType"]);
        $healthTokens = test_input($_GET["healthTokens"]);
        $expTokens = test_input($_GET["expTokens"]);
        $supplyTokens = test_input($_GET["supplyTokens"]);


        $charName = $_POST['charName'];
        $charType = $_POST['charType'];
        $healthTokens = $_POST['healthTokens'];
        $expTokens = $_POST['expTokens'];
        $supplyTokens = $_POST['supplyTokens'];

        if (strtolower($password) == "php123")
        {
            $goldSpent = $healthTokens / 10 + $expTokens / 2 + $supplyTokens / 25;

            print("<h1>You have created $charName the $charType!</h1>");
            print("<p>$charName has $healthTokens health tokens,
                        $expTokens experience tokens, and 
                        $supplyTokens supply tokens.</p>");
            print("<p>$charName has spent $goldSpent gold pieces.</p>");
        }
        else
        {
            print ("<p>Sorry! That password is NOT correct. Please try again</p>");
        }
?>

【问题讨论】:

  • test_input 定义在哪里?
  • test_input 不是内置的 PHP 函数。它没有在这段代码中定义,并且在此之前您没有包含任何可以定义它的文件,所以它没有定义。如果您从另一个文件复制此代码,可能您错过了包含?
  • 你可能还需要一个 if\else 来获取和发布
  • 我没有看到你在哪里分配了$password
  • ($_SERVER["REQUEST_METHOD"] == "GET"); 你忘记了if 并在条件结束条件块后使用;,基本上这一行除了返回真或假之外什么都不做。如果它确实做了一些事情,这些将不起作用$_POST['charName']。但它不是(你可能打算在这里 if/else)....print(..) 不需要这些括号作为它的语言结构而不是函数(但是它可以与它们一起使用)

标签: php function syntax-error undefined-function


【解决方案1】:

您调用了一个未在您的代码中定义的函数:

$charName = test_input($_GET["charName"]);

该函数可能在另一个文件中定义,而您没有包含在脚本中。

【讨论】:

  • 还有很多。
猜你喜欢
  • 1970-01-01
  • 2021-10-18
  • 1970-01-01
  • 2018-11-16
  • 2017-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多