0

我在 index.php 页面的中途有以下 HTML:

<form action="" method="post"><input type="submit" value="Reset Game" class="reset-button" title="Admitting defeat?"></form>

在我的页面顶部,我有以下检查:

if (isset($_POST["submit"]) {
    if ($_POST["submit"] === "Reset Game"] {
        $_SESSION["word"] = generate_word("dictionary.txt");
        $_SESSION["word-progress"] = turn_to_underscores($_SESSION["word"]);
    }
}

它为我的刽子手游戏生成了单词,以及带下划线的版本。以下是这些功能:

    /**
     * Generate a random word from the given dictionary file
     * @param $filename Name of the dictionary file
     * @return Random word
     */
    function generate_word($filename) {
        $dictionary_file = new SplFileObject($filename);
        $dictionary_file->seek(rand(0, 80367));

        return trim($dictionary_file->current());
    }

    /**
     * Accepts a word and returns it as underscores for obfuscation
     * @param $word A given word
     * @return Returns the word as underscores
     */
    function turn_to_underscores($word) {
        $underscored_word = "";

        for ($i = 0; $i < strlen($word); $i++) {
            $underscored_word .= "_";
        }

        return $underscored_word;
    }

我打电话带来的require "functions.php";

我到底做错了什么?

4

3 回答 3

5

你的提交按钮没有 name 属性,所以它不会是一个成功的控件,也不会出现在提交的数据中(当然不是 as $_POST["submit"])。

于 2013-02-19T15:33:26.273 回答
1

给表单输入name="submit"一个。submit

于 2013-02-19T15:34:17.063 回答
0

检查您的 php_error.log 文件。它应该说明您如何尝试访问未定义的索引“提交”。

问题是没有提交键,因为您没有为提交输入提供“名称”值。

于 2013-02-19T15:37:46.010 回答