当用户提交他/她的号码时,我的代码的 php 部分没有做正确的操作,例如,如果用户提交 5,我希望 rand 函数随机输出 5 作为所选数字;但是,我的代码有时有效,有时无效。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>
choose a die number
</title>
</head>
<center>
<body>
<h1>Choose a die number</h1>
<form method = "post" action="choosedie.php"/>
<!--If the user selects a number of sides the die is suppose to have
rand should go through and pick the number randomly, and echo out the
number that was entered by the user-->
Please choose how many sides a die should have from 1 through 6:
<br/>
<input type = "text" name = "roll"/>
<?php
//Roll a random dice from 1 through 6:
$roll = rand(1,6);
// Add random variable to do comparison on.
有没有办法让我在这里比较 rand 而不必创建另一个变量?
$random = rand(1,6);
// If $roll is equal to $random echo the output out to the user.
If ($roll == $random)
{
echo "<br/>Here is the random $roll with the appropriate maximum value $random\n";
如果用户选择 5,我希望它回显 5,但我得到不同的值?
}
?>
</body>
</center>
</html>