我是 PHP 新手,我正在开发一个随机数游戏。如果用户猜对了数字,他就会得到一分。但是,我无法向用户说明这一点。这是我的游戏代码:
:<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>result</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="main"></div>
<div id="enterNumber">
<?php
$number_actual = rand(1, 20);
$number_guess = $_REQUEST["inputnumber"];
echo "You chose: " . $number_guess . "<br />";
echo "The random number is: " . $number_actual . "<br />";
if ($number_guess == $number_actual)
echo "You guessed <b>Correctly!</b>";
elseif ($number_guess < $number_actual)
{
echo "You are too <b>Low</b>!";
echo "<br />";
echo "<br />";
echo "Try guessing again...";
echo "<form>
<input type='text' name='inputnumber' />
<input type='submit' value='Guess' />
</form>";
}
elseif ($number_guess > $number_actual)
{
echo "You are too <b>High</b>!";
echo "<br />";
echo "<br />";
echo "Try guessing again...";
echo "<form>
<input type='text' name='inputnumber' />
<input type='submit' value='Guess' />
</form>";
}
?>
</div>
</body>
</html>
这是给用户一个点的代码,但我在将它们加在一起时遇到了问题!
$query = mysql_query("SELECT * FROM quiz WHERE username='$username'");
$insert = "UPDATE `users` SET `points` = (`points` + 1) WHERE `username` = '".$username."'";
mysql_query($insert);
header('location: succes.php');
}
}
?>
当我尝试添加它们时,我是这样做的:
<?php
$number_actual = rand(1, 20);
$number_guess = $_REQUEST["inputnumber"];
echo "You chose: " . $number_guess . "<br />";
echo "The random number is: " . $number_actual . "<br />";
if ($number_guess == $number_actual)
$query = mysql_query("SELECT * FROM quiz WHERE username='$username'");
$insert = "UPDATE `users` SET `points` = (`points` + 1) WHERE `username` = '" . $username . "'";
mysql_query($insert);
header('location: succes.php');
}
echo "You guessed <b>Correctly!</b>";
elseif ($number_guess<$number_actual)
{
echo "You are too <b>Low</b>!";
echo "<br />";
echo "<br />";
echo "Try guessing again...";
echo "<form>
<input type='text' name='inputnumber' />
<input type='submit' value='Guess' />
</form>";
}
elseif ($number_guess>$number_actual)
{
echo "You are too <b>High</b>!";
echo "<br />";
echo "<br />";
echo "Try guessing again...";
echo "<form>
<input type='text' name='inputnumber' />
<input type='submit' value='Guess' />
</form>";
}
?>