hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Error Question
Reply

Forum Jump

Error Question

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-16-2002, 05:04 PM
Falco1199 Falco1199 is offline
WHT 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



Sponsored Links
  #2  
Old 09-16-2002, 05:12 PM
bowhuntr bowhuntr is offline
Newbie
 
Join Date: Aug 2002
Posts: 8
I'm just learning this stuff, but it looks like you are missing some " on line 21

  #3  
Old 09-16-2002, 05:31 PM
Falco1199 Falco1199 is offline
WHT Addict
 
Join Date: Apr 2002
Location: Cube Galaxy HQ
Posts: 104
if ($num == $number)

quotes??

__________________
:-D

Sponsored Links
  #4  
Old 09-16-2002, 05:44 PM
bowhuntr bowhuntr is offline
Newbie
 
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>" );

  #5  
Old 09-16-2002, 05:57 PM
Lats Lats is offline
Web Hosting Master
 
Join Date: Jan 2002
Location: Melbourne, AU
Posts: 740
Considering matching brackets as a first step.


Lats...

__________________
Lats...

  #6  
Old 09-16-2002, 06:21 PM
tapster tapster is offline
WHT 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


  #7  
Old 09-16-2002, 07:08 PM
Earthnet Earthnet is offline
Newbie
 
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.


  #8  
Old 09-19-2002, 02:41 AM
jtrovato jtrovato is offline
Aspiring 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

John

__________________
John Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  #9  
Old 09-19-2002, 02:43 AM
jtrovato jtrovato is offline
Aspiring 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.

  #10  
Old 09-19-2002, 02:45 AM
jtrovato jtrovato is offline
Aspiring 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.

  #11  
Old 09-19-2002, 08:14 AM
michaeln michaeln is offline
Web 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 || $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>
!is_integer($number) had to be removed as form input is passed as a string and therefor will always return false.

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/");
?>

  #12  
Old 09-19-2002, 11:24 AM
Ultravox Ultravox is offline
WHT Addict
 
Join Date: Sep 2002
Posts: 114
Quote:
if (IsSet($number) {
this is your line 13
correct it to
if (IsSet($number)) {

It will solve your purpose.

Reply

Related posts from TheWhir.com
Title Type Date Posted
In an Attempt to Combat Malware, Microsoft Brings Down Good and Bad Customers of DNS Service No-IP Web Hosting News 2014-07-03 12:24:18
Admin Error Brings Down Joyent’s Ashburn Data Center Web Hosting News 2014-05-28 10:18:18
Unusual DNS Error Leads to Internet Outage in China Web Hosting News 2014-01-21 12:16:24
Lengthy Outages for Hacker News, FastHosts Web Hosting News 2014-01-06 09:56:36
Expired SSL Certificate Brings Down Windows Azure Cloud Web Hosting News 2013-02-25 10:38:00


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?