Results 1 to 12 of 12

Thread: Error Question

  1. #1
    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

  2. #2
    I'm just learning this stuff, but it looks like you are missing some " on line 21

  3. #3
    Join Date
    Apr 2002
    Location
    Cube Galaxy HQ
    Posts
    104
    if ($num == $number)

    quotes??
    :-D

  4. #4
    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. #5
    Join Date
    Jan 2002
    Location
    Melbourne, AU
    Posts
    740
    Considering matching brackets as a first step.


    Lats...
    Lats...

  6. #6
    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. #7
    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. #8
    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. #9
    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. #10
    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. #11
    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. #12
    if (IsSet($number) {
    this is your line 13
    correct it to
    if (IsSet($number)) {

    It will solve your purpose.

  13. Newsletters

    Subscribe Now & Get The WHT Quick Start Guide!

Related Posts from theWHIR.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •