I am new to php and i wish to develop a browser based game. Anyway, i encountered a problem. Here is my code:
<div id ="Ship_choice_div">
<?php
print "Select the ship you wish to equip:<br>";
print "<select name ='shipchoice' lengh = '20'>";
$shipinfo = "Select * from ship_inventory where id=$playerid";
$shipinfo2 = mysql_query($shipinfo) or die("Could not select anything from ships table");
while ($shipinfo3=mysql_fetch_array($shipinfo2))
{
print"<option>$shipinfo3[type]</option>";
}
print"</select><br>";
print"</form>";
?>
</div>
<?php
if (isset($_POST['shipchoice']))
{ $ship= $_POST['shipchoice'];
}
switch($ship) {
case 'frigate':
echo "frigate";
break;
case 'destroyer':
echo "destroyer";
break;
}
?>
It doesn't seem to get the value selected from the combo box into the variable $ship. Do i need to make a button to insert $_POST['shipchoice'] into variable $ship? If so, i need to write a new .php script only with this code: if (isset($_POST['shipchoice'])) { $ship= $_POST['shipchoice']; } ???How can i make a button that inserts the variable $ship with $_POST['shipchoice'] all on the same .php page?? What should the action=" " of a button statement be?
I am sorry if i assaulted you with so many questions. The error i get is Undefined variable ship on line case 'frigate': and Undefined variable ship on line case: 'destroyer'. I tried to explain my issue as nice as i could