我正在研究基於文本的在線遊戲(這是非常不完整的),並且我主要使用PHP。在我的HTML中,我有一個用於我的遊戲命令的表單(文本輸入),但它不會顯示。這是我的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 ,我試圖移植到瀏覽器的一個分支,但可怕的失敗...
如果去掉'包括( 'game.php')'沒有問題消失? – Barmar
當我加載你的網頁時,它釘住了我的CPU。 – Barmar
是的,那也是我的想法。雖然我不確定。當我上次嘗試時,它沒有得到任何結果。 – dumpong