hi, i have spent more than whole day trying to figure out what is wrong in this php sript LINE 3 AND 14, ihave changed the quotes, but it didnt work, it works normal when you enter the date to GUESS THE NUMBER, but in the start page the ERROR APPEAR, please can any one help me on that? thank you every body....:))

here is the code:
1- <?php
2- $num_to_guess=42;
3- $num_tries = (!isset($_POST["num_tries"])) ? $num_tries + 1 : 0;
4- $message = "";
5- if (!isset($_POST["guess"])){
6- $message = "WELCOME TO tHE GUESSING MAChINE!";
7- } else if ($_POST["guess"] >$num_to_guess) {
8- $message = "$_POST[guess] is too big! TRY a smaller number";
9- }else if ($_POST["guess"] < $num_to_guess) {
10- $message = "TOO SMALL OR EMPTY";
11- } else {
12- $message = "WELL DONE!";
13- }
14 $guess = $_POST["guess"];
15- ?>
16- <html>
17- <head>
18- <title>SAVE STATE WITH HIDDEN FIELD</title>
19- </head>
20- <body>
21 <h1>
22- <?php echo $message ?>
23- </h1>
24- <form action="<?php echo $_SERVER ?>" method="POST">
25- <p><strong>Type your guess Here: </strong>
26- <input type="text" name="guess" value="<?php echo $guess ?>" >
27- <input type="hidden" name="num_tries" value="<?php echo $num_tries ?>" >
28- <p><input type="submit" value="submit your guess" /></p>
29- </form>
30- </body>
31- </html>

FOLLOWING ERROR
Notice: Undefined variable: num_tries in C:\wamp\www\phptest\hiddenfield.php on line 3

Notice: Undefined index: guess in C:\wamp\www\phptest\hiddenfield.php on line 14

Try the following code:

<?php
$num_to_guess=42;
$num_tries=0;
$num_tries = (!isset($_POST["num_tries"])) ? $num_tries + 1 : 0;
$message = "";
if (!isset($_POST["guess"])){
 $message = "WELCOME TO THE GUESSING MAChINE!";
 } else if ($_POST["guess"] >$num_to_guess) {
 $message = "$_POST[guess] is too big! TRY a smaller number";
 }else if ($_POST["guess"] < $num_to_guess) {
	$message = "TOO SMALL OR EMPTY";
 } else { 
	$message = "WELL DONE!";
 }
(isset($_POST["guess"])) ? $guess = $_POST["guess"] : $guess = '';
?>
<html>
<head>
<title>SAVE STATE WITH HIDDEN FIELD</title>
</head>
<body>
<h1>
<?php echo $message ?>
</h1>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
<p><strong>Type your guess Here: </strong>
<input type="text" name="guess" value="<?php echo $guess ?>" >
<input type="hidden" name="num_tries" value="<?php echo $num_tries ?>" >
<p><input type="submit" value="submit your guess" /></p>
</form>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.