Form Data Handling
Posted: Thu Dec 22, 2011 4:48 pm
Hello im new to this forum and also PHP. I started playing around with Dreamweaver, so i decided to make something small just to get to grips with website building. So I made a dice game where you need to choose how many sides the dice will have and what number you think it will be and when I submit the form data it resets everything so that you have to input all the data again. How can I stop it from doing this? Thanks for any help in advance, here is my code...
Code: Select all
<html>
<head>
<title>Test</title>
<style type="text/css">
.Verdana {
font-family: Verdana;
color: #CCC;
font-size: 9px;
font-weight: normal;
font-variant: normal;
}
.TextBox {
font-family: Verdana;
font-size: 9px;
color: #CCC;
background-color: #333;
border: 1px solid #666;
}
.BetBox {
font-family: Verdana;
font-size: 9px;
color: #CCC;
background-color: #333;
border: 1px solid #666;
width: 67px;
height: 14px;
}
.Header {
font-family: Verdana;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
color: #FFF;
background-color: #191919;
border: thin none #000;
background-image: none;
}
.MinorHeader {
font-family: Verdana;
font-size: 10px;
font-style: normal;
line-height: normal;
font-weight: bold;
font-variant: normal;
text-transform: none;
color: #FFF;
background-color: #333;
border-top-style: solid;
border-right-style: none;
border-bottom-style: none;
border-left-style: solid;
border-top-width: thin;
border-left-width: thin;
border-top-color: #000;
border-left-color: #000;
border-right-width: thin;
border-bottom-width: thin;
border-right-color: #000;
border-bottom-color: #000;
}
.tdBorder {
border: thin solid #000;
background-color: #333;
font-size: 15px;
}
.ButtonStyle {
font-family: Verdana;
font-size: 10px;
background-color: #999;
border: thin solid #666;
color: #000;
height: 18px;
}
</style>
</head>
<body bgcolor="#000000" text="#FFFFFF">
<?php
Function Random($Max)
{
$A=Rand(1, $Max);
Return $A;
}
?>
<div align="center">
<form action="Index.PHP" method="post">
<font color="#CCCCCC" size="-1">
<?php
If ($_POST["amount"] > 0)
If ($_POST["sides"] > 1)
Echo Random($_POST["sides"]);
Else
Echo "*You cannot roll a dice with less than 2 sides!";
?>
</font>
<table border="0" cellpadding="0" cellspacing="1" bgcolor="#990000">
<tr><td colspan="2" class="tdBorder"><div align="center" class="Header">Dice Game</div></td></tr>
<tr><td class="tdBorder"><div align="right"><font size="1" class="Verdana">Sides:</font></div></td>
<td class="tdBorder">
<input type="number" name="sides" class="TextBox" value="0"/>
</td></tr>
<tr><td class="tdBorder"><div align="right"><font size="1" class="Verdana">Number:</font></div></td>
<td class="tdBorder"><input type="number" name="num" class="TextBox" value="0"/></td></tr>
<tr><td colspan="2" bgcolor="#FFFFFF" class="tdBorder">
<div align="center">$
<input type="number" name="amount" class="BetBox"/> <input type="submit" name="Bet" value="Bet!" class="ButtonStyle"/>
</div>
</td></tr>
</table>
</form>
</div>
</body>
</html>