Results 1 to 12 of 12
Thread: Error Question
Hybrid View
-
09-16-2002, 05:04 PM #1WHT Addict
- Join Date
- Apr 2002
- Location
- Cube Galaxy HQ
- Posts
- 104
Error Question
I just made a random practice script to test my knowledge of PHP after learning it. It comes up with an error... Here's the script:
<html>
<head>
<title>PHP Test!</title>
</head>
<body>
Try to guess my number! Good luck.<br /><br />
<form action="<?php $PHP_SELF ?>">
Print a number between 1 and 6:<input type="text" length="10" name="number"><br />
<input type="submit" value="Let's see!"><br />
</form>
<?php
if (IsSet($number) {
if (!is_integer($number) or $number < 1 or $number > 6)
print("Your input was not a number from one to six.");
else
{
mt_srand((double) microtime() * 1000000);
$num = mt_rand(1,6);
if ($num == $number)
print("A WINNER! <a href="winner.php">Click here to claim your prize!</a>);
else
print("Sorry, that's not that number");
}
}
?>
</body>
</html>
And here's my error:
Parse error: parse error in /home/virtual/site141/fst/var/www/html/phptest.php on line 13
What's wrong?:-D
-
09-16-2002, 05:12 PM #2Newbie
- Join Date
- Aug 2002
- Posts
- 8
I'm just learning this stuff, but it looks like you are missing some " on line 21
-
09-16-2002, 05:31 PM #3WHT Addict
- Join Date
- Apr 2002
- Location
- Cube Galaxy HQ
- Posts
- 104
if ($num == $number)
quotes??:-D
-
09-16-2002, 05:44 PM #4Newbie
- Join Date
- Aug 2002
- Posts
- 8
yes, look at the quotes in the print statement for the winner line (21)
shouldn't it be:
print("A WINNER! <a href="winner.php">Click here to claim your prize!</a>" );
-
09-16-2002, 05:57 PM #5Web Hosting Master
- Join Date
- Jan 2002
- Location
- Melbourne, AU
- Posts
- 740
Considering matching brackets as a first step.
Lats...Lats...
-
09-16-2002, 06:21 PM #6WHT Addict
- Join Date
- Sep 2002
- Location
- San Francisco, CA
- Posts
- 103
if (IsSet($number) {
has the closing bracket missing after $number as Lats pointed out...
you also want to escape the " inside your href tag or use single quote around the filename
-
09-16-2002, 07:08 PM #7Newbie
- Join Date
- Sep 2002
- Posts
- 5
Fix:
print("A WINNER! <a href="winner.php">Click here to claim your prize!</a> );
to
print("A WINNER! <a href=\"winner.php\">Click here to claim your prize!</a>" );
if (IsSet($number) {
to
if (IsSet($number)) {
To make the script work correctly (after all the parsing errors are fixed) use is_numeric instead of is_integer.
-
09-19-2002, 02:41 AM #8Aspiring Evangelist
- Join Date
- Aug 2002
- Location
- Long Island
- Posts
- 427
I don't know about you guys but the
if (something) {
}
Statement kills me
20 years ago when I learned C on an Apple IIe and from then on I have always used the following structure
If (c1ondition)
{
if (Some thing else is true)
{
Do some more things
}
}
else
{
do something else
}
I had to write huge apps and I’ll tell you one thing, to debug would have been crazy if I didn’t see what statements went with what code.
Some food for thought
JohnJohn Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.
-
09-19-2002, 02:43 AM #9Aspiring Evangelist
- Join Date
- Aug 2002
- Location
- Long Island
- Posts
- 427
well it looks like my tabs didn't work. well this is what I ment sorry guys
If (c1ondition)
{
if (Some thing else is true)
{
Do some more things
}
}
else
{
do something else
}John Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.
-
09-19-2002, 02:45 AM #10Aspiring Evangelist
- Join Date
- Aug 2002
- Location
- Long Island
- Posts
- 427
you get the idea. no spaces or tabs allowed here. lol Maybe I should learn HTML!!!!!
If (c1ondition)
{
-----> if (Some thing else is true)
----->{
----->----->Do some more things
----->}
}
else
{
----->do something else
}John Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.
-
09-19-2002, 08:14 AM #11Web Hosting Master
- Join Date
- Nov 2001
- Posts
- 857
Ok there are a coupld of errors in your script. Here is a working version:
PHP Code:<html>
<head>
<title>PHP Test!</title>
</head>
<body>
Try to guess my number! Good luck.<br /><br />
<form action="<?php $PHP_SELF ?>" method="post">
Print a number between 1 and 6:<input type="text" maxlength="1" length="10" name="number"><br />
<input type="submit" value="Let's see!"><br />
</form>
<?php
if (IsSet($number))
{
if ($number < 1 || $number > 6)
print("Your input was not a number from one to six. <BR>You input $number");
else
{
mt_srand((double) microtime() * 1000000);
$num = mt_rand(1,6);
if ($num == $number)
print("A WINNER! <a href=\"winner.php\">Click here to claim your prize!</a>");
else
print("Sorry, that's not that number");
}
}
?>
</body>
</html>
You forgot a quote at the end of this line:
print("A WINNER! <a href="winner.php">Click here to claim your prize!</a> );
You had also put quotes in the middle of the above string without backslashes in front. It should look like this:
print("A WINNER! <a href=\"winner.php\">Click here to claim your prize!</a>");
Regards,
Michael<?
header("Location: http://www.hostevolve.com/");
?>
-
09-19-2002, 11:24 AM #12WHT Addict
- Join Date
- Sep 2002
- Posts
- 114
if (IsSet($number) {
correct it to
if (IsSet($number)) {
It will solve your purpose.