problem with output of this code
i wrote this code. in this code we user guess a number then program checked the number with the number that i gite to it and print appropriates message. when i start program it shows welcome that is true but when i entered number in it always it shows little in output but it isn't true.
$val = '42';
$gues ;
if(!isset($gues))
$mess = "welcome<br>";
elseif($gues > $val)
$mess = "bigr<br>";
elseif($gues < $val)
$mess = "little<br>";
else
$mess = "win<br>";
$gues = @(int) $gues;
?>
<html>
<head><title>bazi riazi</title></head>
<body>
<h1>
<?php print $mess;
?>
</h1>
<form method="POST">
type you gues here:<input ty开发者_高级运维pe="text" name='gues'>
</form>
</body>
</html>
How your var $gues
get value from form? Did you use $_POST['gues']
first?
Script always print little
because probably variable $gues
was not initialized any value (default is zero, I suppose...).
This code should work (untested, though):
$val = '42';
$gues = int($_POST['gues']);
if (!isset($gues))
{
$mess = "welcome<br>";
}
elseif($gues > $val)
{
$mess = "bigr<br>";
}
elseif($gues < $val)
{
$mess = "little<br>";
}
else
{
$mess = "win<br>";
}
精彩评论