Reputation: 151
I am working on a text-based online game (that is horribly incomplete), and I'm using PHP mainly. In my HTML I have a form (text input) for commands for my game, but it just won't show up. This is my 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>
So it's really the FORM and the INPUT that screws me over since it doesn't show up. I also have this as my CSS, if it helps:
.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;
}
And of course I have my game.php
but I don't feel like that's the problem.
Any help would be appreciated.
EDIT: Based on people's answers, it's probably the PHP. Here's the entire code for the game.php file, I have no idea what's wrong.
<?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>";
?>
Really, it's just a branch off of http://www.hackingwithphp.com/21/4/2/text-game-v1 that I tried to port to browsers but it failed horribly...
Upvotes: 3
Views: 1980
Reputation: 97152
It shows up fine in Chrome and in Firefox. See below.
.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;
}
<div class="container">
<div class="main">
</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>
</div>
Upvotes: 1