I am trying to design a small dice rolling website, however whenever I try to display my modified dice roll it comes with a much longer string of integers then I am expecting.
<?php
$number = 0;
echo "Name: {$_POST['name']}<br />";
echo "Subject: {$_POST['subject']}<br />";
echo "Message: {$_POST['message']}<br /><br />";
if(strcmp($_POST['die'],"D100") ){
echo "D100 <br />";
$number = 0;
$number = (mt_rand ( 1 , 100 )* + $_POST['amount'] ) + $_POST['modifier'];
echo $number;
}
if(strcmp($_POST['die'],"D20") ){
$number = 0;
$number = (mt_rand ( 1 , 20 )* + $_POST['amount'] ) + $_POST['modifier'];
echo $number;
}
if(strcmp($_POST['die'],"D12") ){
$number = 0;
$number = (mt_rand ( 1 , 12 )* + $_POST['amount'] ) + $_POST['modifier'];
echo $number;
}
if(strcmp($_POST['die'],"D10") ){
$number = 0;
$number = (mt_rand ( 1 , 10 )* + $_POST['amount'] ) + $_POST['modifier'];
echo $number;
}
if(strcmp($_POST['die'],"D8") ){
$number = 0;
$number = (mt_rand ( 1 , 8 )* + $_POST['amount'] ) + $_POST['modifier'];
echo $number;
}
if(strcmp($_POST['die'],"D6") ){
$number = 0;
$number = (mt_rand ( 1 , 6 )* + $_POST['amount'] ) + $_POST['modifier'];
echo $number;
}
if(strcmp($_POST['die'],"D3") ){
$number = 0;
$number = (mt_rand ( 1 , 3 )* + $_POST['amount'] ) + $_POST['modifier'];
echo $number;
}
?>
My HTML:
<!DOCTYPE html>
<html>
<body>
<form action="action_page.php" method="POST">
Name:<br>
<input type="text" name="name">
<br>
Subject:<br>
<input type="text" name="subject">
<br>
<textarea rows="6" cols="60" name="message">
</textarea>
<br>
Amount:
<input type="number" name="amount">
Dice Roll:
<select name="die">
<option value="D100">D100</option>
<option value="D20">D20</option>
<option value="D12">D12</option>
<option value="D10">D10</option>
<option value="D8">D8</option>
<option value="D6">D6</option>
<option value="D3">D3</option>
</select>
Modifier:
<input type="number" name="modifier">
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page called "action_page.php".</p>
</body>
</html>
I can display all the values fine, but when I start using the mt_rand function it starts throwing massively long strings of integers, and I cant seem to figure out a way. Also I dont think my compre strcmp works half the time. Any help would be greatly appreciated thank you.
I am hosting this on a raspberry pi running apache2
Aucun commentaire:
Enregistrer un commentaire