HTML表单中的文本输入不会显示

时间:2015-08-25 04:31:42

标签: php html css forms input

我正在开发基于文本的在线游戏(非常不完整),我主要使用PHP。在我的HTML中,我有一个表单(文本输入)用于我的游戏命令,但它只是不会出现。这是我的HTML:

<div class="container">
    <div class="main">
    <?php
        include_once 'game.php';
    ?>
    </div>
    <FORM NAME="form1" METHOD="POST" ACTION="">
        <INPUT TYPE="TEXT" VALUE="" name="input"
            style="width: 600; position: absolute; bottom: 0; z-index: 2;">
        </INPUT>
    </FORM>
    <?php
        $input = $_POST["input"];
    ?>
</div>

所以它真的是FORM和INPUT,因为它没有出现,所以它让我感到震惊。我也有这个作为我的CSS,如果它有帮助:

.main {
    width: 600px;
    height: 400px;
    background-color: white;
    border: 1px solid black;
    position: absolute;
    top:0;
    left: 0;
    right: 0;
    z-index: 1;
}

.container {
    width: 602px;
    height: 500px;
    background-color: white;
    border: 1px solid blue;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 0;
    margin: 0 auto;
}

当然我有game.php,但我不觉得这就是问题所在。

任何帮助都将不胜感激。

编辑:基于人们的答案,它可能是PHP。这是game.php文件的完整代码,我不知道是什么错误。

<?php
include_once 'index.php';
$World = simplexml_load_file("gameworld.xml");
$CurrentPos = 0;
$Done = 0;
print "<br>";
printplace();
function printplace() {
    GLOBAL $World, $CurrentPos;
    $Room = $World->ROOM[$CurrentPos];
    $Name = $Room->NAME;
    $Desc = wordwrap((string)$Room->DESC);
    print "$Name<br>";
    print str_repeat('-', strlen($Name));
    print "<br>$Desc<br>";
    if ((string)$Room->NORTH != '-') {
        $index = (int)$Room->NORTH;
        print "North: {$World->ROOM[$index]->NAME}<br>";
    }
    if ((string)$Room->SOUTH != '-') {
        $index = (int)$Room->SOUTH;
        print "South: {$World->ROOM[$index]->NAME}<br>";
    }
    if ((string)$World->ROOM[$CurrentPos]->WEST != '-') {
        $index = (int)$Room->WEST;
        print "West: {$World->ROOM[$index]->NAME}<br>";
    }
    if ((string)$World->ROOM[$CurrentPos]->EAST != '-') {
        $index = (int)$Room->EAST;
        print "East: {$World->ROOM[$index]->NAME}<br>";
    }
    print "<br>";
}

while (!$Done) {
    print "<br>"; // add another line break after the user input

    $input = split(' ', $input);

    switch(trim($input[0])) {
        case 'north':
            if ((string)$World->ROOM[$CurrentPos]->NORTH != '-') {
                $CurrentPos = (int)$World->ROOM[$CurrentPos]->NORTH;
                printplace() ;
            } else {
                print "You cannot go north!<br>";
            }
            break;
        case 'south':
            if ((string)$World->ROOM[$CurrentPos]->SOUTH != '-') {
                $CurrentPos = (int)$World->ROOM[$CurrentPos]->SOUTH;
                printplace() ;
            } else {
                print "You cannot go south!<br>";
            }
            break;
        case 'west':
            if ((string)$World->ROOM[$CurrentPos]->WEST != '-') {
                $CurrentPos = (int)$World->ROOM[$CurrentPos]->WEST;
                printplace() ;
            } else {
                print "You cannot go west!<br>";
            }
            break;
        case 'east':
            if ((string)$World->ROOM[$CurrentPos]->EAST != '-') {
                $CurrentPos = (int)$World->ROOM[$CurrentPos]->EAST;
                printplace() ;
            } else {
                print "You cannot go east!<br>";
            }
            break;
        case 'look':
            printplace() ;
            break;
        case 'quit':
            $Done = 1;
            break;
    }
}

print "<br>Thanks for playing!<br>";
?>

真的,它只是http://www.hackingwithphp.com/21/4/2/text-game-v1的一个分支 我试图移植到浏览器,但它失败了......

0 个答案:

没有答案