PHP Parse error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BWGames

    PHP Parse error

    Can someone tell me whats up with this code please?

    $update_query = "UPDATE users SET creditremaining = creditremaining - " .
    $_REQUEST['MsgCount'] . "WHERE mobilenumber = " . $_REQUEST['From'] . "";

    where creditremaining is a MySQL table field, and $_REQUEST['XXX'] is a
    HTTP GET variable.

    Thanks,

    Ben
    --
    BWGames
    to email change de.news to de-news
  • Alvaro G Vicario

    #2
    Re: PHP Parse error

    *** BWGames wrote/escribió (Wed, 14 Apr 2004 10:08:48 +0100):[color=blue]
    > $update_query = "UPDATE users SET creditremaining = creditremaining - " .
    > $_REQUEST['MsgCount'] . "WHERE mobilenumber = " . $_REQUEST['From'] . "";[/color]

    You should have copied the PHP error you get: I get none. In any case,
    please note there isn't a space before WHERE so the database query won't
    work.

    Also, you should use mysql_escape_st ring() because you never know what
    $_REQUEST will contain.

    --
    --
    -- Álvaro G. Vicario - Burgos, Spain
    --

    Comment

    • Ashmodai

      #3
      Re: PHP Parse error

      BWGames scribbled something along the lines of:
      [color=blue]
      > Can someone tell me whats up with this code please?
      >
      > $update_query = "UPDATE users SET creditremaining = creditremaining - " .
      > $_REQUEST['MsgCount'] . "WHERE mobilenumber = " . $_REQUEST['From'] . "";
      >
      > where creditremaining is a MySQL table field, and $_REQUEST['XXX'] is a
      > HTTP GET variable.[/color]

      'cept for the missing space before "WHERE" there is no problem. Maybe
      you missed the final semicolon in the line before that?
      In most cases parsing errors are caused by unclosed brackets or missing
      semi-colons one row before the one deemed faulty in the error message.

      --
      Alan Plum, WAD/WD, Mushroom Cloud Productions

      Comment

      • BWGames

        #4
        Re: PHP Parse error

        On Wed, 14 Apr 2004 11:44:18 +0200, in comp.lang.php, Ashmodai wrote:
        [color=blue]
        > BWGames scribbled something along the lines of:
        >[color=green]
        >> Can someone tell me whats up with this code please?
        >>
        >> $update_query = "UPDATE users SET creditremaining = creditremaining - " .
        >> $_REQUEST['MsgCount'] . "WHERE mobilenumber = " . $_REQUEST['From'] . "";
        >>
        >> where creditremaining is a MySQL table field, and $_REQUEST['XXX'] is a
        >> HTTP GET variable.[/color]
        >
        > 'cept for the missing space before "WHERE" there is no problem. Maybe
        > you missed the final semicolon in the line before that?
        > In most cases parsing errors are caused by unclosed brackets or missing
        > semi-colons one row before the one deemed faulty in the error message.[/color]

        That's funny, as I get:

        Parse error: parse error in /www/page.php on line 16, where line 16 is:

        $update_query = "UPDATE users SET creditremaining = creditremaining - " .
        $_REQUEST['MsgCount'] . " WHERE mobilenumber = " . $_REQUEST['From'] . "";

        The line after that is
        If ($update_result = mysql_query($up date_query)) {

        I can't see aproblem with either of the lines either..

        Anyone?

        Thanks for the help so far :)

        Ben
        --
        BWGames
        to email change de.news to de-news

        Comment

        • BWGames

          #5
          Re: PHP Parse error

          On Wed, 14 Apr 2004 11:02:57 +0100, in comp.lang.php, BWGames wrote:

          [color=blue]
          > I can't see aproblem with either of the lines either..
          >
          > Anyone?
          >
          > Thanks for the help so far :)
          >
          > Ben[/color]

          (bad form to reply to my own post, but sorry!)

          Ooops sorry!

          The problem was a missing ) in the preceding IF statement.

          Sorry all!

          Ben


          --
          BWGames
          to email change de.news to de-news

          Comment

          • Garp

            #6
            Re: PHP Parse error


            "BWGames" <de.news@bwgame s.net> wrote in message
            news:dz2qi3oksa ti$.dlg@tehlan. co.uk...[color=blue]
            > Can someone tell me whats up with this code please?
            >
            > $update_query = "UPDATE users SET creditremaining = creditremaining - " .
            > $_REQUEST['MsgCount'] . "WHERE mobilenumber = " . $_REQUEST['From'] . "";
            >
            > where creditremaining is a MySQL table field, and $_REQUEST['XXX'] is a
            > HTTP GET variable.[/color]

            In addition to the other comments, I'm sure your 'mobilenumber' field
            oughtn't be numeric (you won't be carrying out any math on it, and you'll
            lose leading zeroes) - it should be encased in single quotes if it's a
            string.

            FWIW, I cut&pasted that line into my test file and syntactically, it works
            fine.

            Garp


            Comment

            • Eric Bohlman

              #7
              Re: PHP Parse error

              BWGames <de.news@bwgame s.net> wrote in news:cu9ua22i3i 1s.dlg@tehlan.c o.uk:
              [color=blue]
              > Ooops sorry!
              >
              > The problem was a missing ) in the preceding IF statement.
              >
              > Sorry all![/color]

              It's *very* important to realize that a parser can't detect the exact point
              at which an error occurs. All it can do is detect the point where its
              input stops making sense according to the language's grammar; this is
              almost always going to occur quite a ways *after* the actual mistake.

              For example, if you leave off the closing parenthesis on an if condition,
              the parser will try to read the next statement as if it was still part of
              the if condition. It won't be able to detect an error until it runs across
              something that can't legally occur inside an if condition, and that may be
              well into the next statement, or even the statement after it.

              Comment

              • Ashmodai

                #8
                Re: PHP Parse error

                Eric Bohlman scribbled something along the lines of:
                [color=blue]
                > BWGames <de.news@bwgame s.net> wrote in news:cu9ua22i3i 1s.dlg@tehlan.c o.uk:
                >
                >[color=green]
                >>Ooops sorry!
                >>
                >>The problem was a missing ) in the preceding IF statement.
                >>
                >>Sorry all![/color]
                >
                >
                > It's *very* important to realize that a parser can't detect the exact point
                > at which an error occurs. All it can do is detect the point where its
                > input stops making sense according to the language's grammar; this is
                > almost always going to occur quite a ways *after* the actual mistake.
                >
                > For example, if you leave off the closing parenthesis on an if condition,
                > the parser will try to read the next statement as if it was still part of
                > the if condition. It won't be able to detect an error until it runs across
                > something that can't legally occur inside an if condition, and that may be
                > well into the next statement, or even the statement after it.[/color]

                That was my point. Usually a missing (closing) bracket or semicolon does
                exactly that, eg:

                if (isset($a) {
                // some code
                }

                (missing bracket after "isset")

                or

                $bar = 10 * 5 + 3
                $foo = $bar;

                (missing semicolon in the first row)

                In the second example the error will occur in the row AFTER the one
                missing the bracket.

                --
                Alan Plum, WAD/WD, Mushroom Cloud Productions

                Comment

                Working...