• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 239
  • Last Modified:

When I go through the error messages I get with this script, it doesn't work at all.

Hello,

I should be getting a form that allows my viewer can guess a number. This is a practice script but should work and doesn't.

a<?php
$num_to_guess = 42;
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 = $_POST["guess"]." is too small! Try a larger number.";
} else if { // must be equivalent
	$message = "Well done!";
}
?>


<html>
<head>
<title>A PHP number guesssing script</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"/></p>
<p><input type="submit" value="submit your guess"/></p>
</form>
</body>
</html>

Open in new window



This is the first error I get -

Parse error: syntax error, unexpected '{', expecting '(' in /Library/WebServer/Documents/numguess.php on line 9

When I change this then I get two others and then I just get a blank browser.

Thanks

WC
0
wchirnside
Asked:
wchirnside
  • 3
  • 2
1 Solution
 
havj123Commented:
There is error in last Else If. Replace it with only Else

It should be like this:

a<?php
$num_to_guess = 42;
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 = $_POST["guess"]." is too small! Try a larger number.";
} else { // must be equivalent
      $message = "Well done!";
}
?>
0
 
wchirnsideAuthor Commented:
Thank you,

At least this changed the error messages that I have been getting.

Now I get this message -


Parse error: syntax error, unexpected T_STRING, expecting ']' in line 21 which in my text editor is this line - <form action="<?php echo $_SERVER["PHP"_SELF"]; ?>" method="POST">

wchirnside
0
 
wchirnsideAuthor Commented:
Thanks for the quick reply.

WC
0
 
havj123Commented:
The next error is because of incorrect double quotes in  $_SERVER["PHP"_SELF"];
Double quote not open close properly.

0
 
wchirnsideAuthor Commented:
Yes, thanks. Before I posted the question I must have looked at the script about 10 times but did not see either error. I am using Text Wrangler as my text editor and was wondering if there is a way to find incorrect code.

WC
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now