parse error in nested query - please help.

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

    parse error in nested query - please help.

    I am having troubles finding the parse error in this script. I've been
    checking for weeks. I am too new to the subject I guess.

    I am trying to show a readord and them have a form at the bottom of the
    page for inputting data to Update the record. I get a parse error that
    points to the last line in the script so I know it is something I am missing
    earlier in the script but doing a line by line it seems fine to me.

    Thanks for any atempt and suggestions.

    Polar :)

    ------------------------------
    <--cut--
    $query = "SELECT sub_id, username, story_title, DATE_FORMAT(dat e_submitted,
    '%m/%d/%y'), category, story FROM Submission WHERE date_processed < 1 LIMIT
    0,1";

    $result = @mysql_query ($query); // Run the query.
    if ($result) { // If OK, display the record.


    echo '<table align="center" cellspacing="5" cellpadding="1" border="0"
    width="500"><sp an><tr><td align="left" width="100">Sto ry ID:</td><td
    align="left" width="100">Nam e</td><td align="left" width="250">Tit le</td><td
    align="left" width="100">Dat e&nbsp;Submitte d</td><td align="left"
    width="50">Cate gory</td></tr><tr><td colspan="5"></span><hr></td></tr>';

    // Fetch and print the record.
    while ($row = mysql_fetch_arr ay($result, MYSQL_NUM)) {
    echo"<tr><td align=\"left\" width=\"100\">"
    ..$row[0]
    .."</td><td align=\"left\" width=\"100\">"
    ..$row[1]
    .."</td> <td align=\"left\"w idth=\"250\">"
    ..$row[2]
    .."</td><td align=\"left\" width=\"50\">"
    ..$row[3]
    .."</td><td align=\"left\" width=\"50\">"
    ..$row[4]
    .."</td></tr><tr><td colspan=\"5\"wi dth=\"500\"><br >"
    ..nl2br($row[5])
    .."</td></tr>\n";
    }
    echo '</table>';
    echo '<hr>';



    if (isset($_POST['submit'])) { // Handle the form.

    if (isset($_POST['accepted']) == 'Y') {
    $acc = $_POST['accepted'];
    echo "<b><p>Grea t A story to pass on!</p></b>";
    $query = "UPDATE Submission SET reader={$_SESSI ON['username']},
    date_processed= NOW(), accepted=$acc WHERE sub_id=$row[0]";

    } elseif (isset($_POST['accepted']) == 'N') {
    $acc = $_POST['accepted'];
    echo "<b><p>Try again with a new story!</p></b>";
    $query = "UPDATE Submission SET reader={$_SESSI ON['username']},
    date_processed= NOW(), accepted=$acc WHERE sub_id=$row[0]";


    $result = @mysql_query ($query); // Run the query.
    if (mysql_affected _rows() == 1) { // If it ran OK.
    echo 'Done';
    include ('includes/footer.html'); // Include the HTML footer.
    exit();


    } else { // If no accepted was selected...
    $accepted = NULL;
    echo '<p><b>You forgot to enter Yes or No for the story
    acceptance!</b></p>';

    }

    }

    ?>


  • Pedro Graca

    #2
    Re: parse error in nested query - please help.

    Polar wrote:[color=blue]
    > I am having troubles finding the parse error in this script. I've been
    > checking for weeks. I am too new to the subject I guess.[/color]

    Count the number of "{" and compare with the number of "}".

    I imagine they'll be different :)

    --
    USENET would be a better place if everybody read: | to email me: use |
    http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
    http://www.netmeister.org/news/learn2quote2.html | header, textonly |
    http://www.expita.com/nomime.html | no attachments. |

    Comment

    • Polar

      #3
      Re: parse error in nested query - please help.

      Thanks Pedro

      I went over that many times - thinking the same thing - and low any beold on
      my second to last bunch of hair I found it

      Now I have a new problem. The query is not updating the record.

      the $_Session['username'] is available as it is posting on top of the screen
      about the form.
      the Now() is evident it should be ok as is Accepted that leaves the
      qualifier of the sud_id?

      ....

      if (isset($_POST['accepted']) == 'Y') {
      $query = "UPDATE Submission SET reader={$_SESSI ON['username']},
      date_processed= NOW(), accepted='Y' WHERE sub_id=$row[0]";
      echo "<b><p>Grea t A story to pass on!</p></b>";

      ....

      is there an error here in my syntax That I am not seeing?

      Thanks for the time and any comments

      Polar :)



      Comment

      • Geoff Berrow

        #4
        Re: parse error in nested query - please help.

        I noticed that Message-ID: <8MkGc.30436$P7 .21937@pd7tw3no > from Polar
        contained the following:
        [color=blue]
        >if (isset($_POST['accepted']) == 'Y') {
        >$query = "UPDATE Submission SET reader={$_SESSI ON['username']},
        >date_processed =NOW(), accepted='Y' WHERE sub_id=$row[0]";
        >echo "<b><p>Grea t A story to pass on!</p></b>";
        >
        >...
        >
        >is there an error here in my syntax That I am not seeing?[/color]

        Not sure you can use isset() like that
        Determine if a variable is declared and is different than null

        And where is $row[0] coming from?

        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Pedro Graca

          #5
          Re: parse error in nested query - please help.

          Polar wrote:[color=blue]
          > Now I have a new problem. The query is not updating the record.
          >
          > the $_Session['username'] is available as it is posting on top of the screen
          > about the form.
          > the Now() is evident it should be ok as is Accepted that leaves the
          > qualifier of the sud_id?
          >
          > ...
          >
          > if (isset($_POST['accepted']) == 'Y') {
          > $query = "UPDATE Submission SET reader={$_SESSI ON['username']},
          > date_processed= NOW(), accepted='Y' WHERE sub_id=$row[0]";
          > echo "<b><p>Grea t A story to pass on!</p></b>";
          >
          > ...
          >
          > is there an error here in my syntax That I am not seeing?[/color]

          Yes, in SQL syntax. I'll leave it up to you to find :)

          You do not show your mysql_query() call and *most importantly* how
          you're checking for errors!

          I usually do (pseudo-code)

          <?php
          $query = "whatever";
          $result = mysql_query($qu ery)
          or die('Error in query [' . $query . ']. The error was: ' . mysql_error());
          ?>



          Hint: is $_SESSION['username'] a string?

          --
          USENET would be a better place if everybody read: | to email me: use |
          http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
          http://www.netmeister.org/news/learn2quote2.html | header, textonly |
          http://www.expita.com/nomime.html | no attachments. |

          Comment

          • 'bonehead

            #6
            Re: parse error in nested query - please help.

            Pedro Graca wrote:[color=blue]
            > I usually do (pseudo-code)
            >
            > <?php
            > $query = "whatever";
            > $result = mysql_query($qu ery)
            > or die('Error in query [' . $query . ']. The error was: ' . mysql_error());
            > ?>
            >
            > Hint: is $_SESSION['username'] a string?[/color]

            Okay I'll hazard a guess on this one. I haven't tested this particular
            solution, but I've occasionally run into similar problems.

            If Polar's $query is holding a string, is it possible that the php
            expressions must be concatenated as they are in Pedro's example? For
            instance, wouldn't you really need to do something like this:

            $query = "UPDATE Submission SET reader='".{$_SE SSION['username']}."',
            date_processed= NOW(), accepted='Y' WHERE sub_id='".$row[0]."'";

            Also, wouldn't you want to do something like

            /*temporary error check line*/
            echo $query;

            Just to make sure the query looks the way it's supposed to?

            Hope this helps.

            Comment

            • Polar

              #7
              Re: parse error in nested query - please help.

              I posted the full script ( I hope ) at the very beginning of the thread.

              Thanks for the info and not just giving me the answer - I have only been
              doing this for about 3 weeks now. So ALL this is new.

              thanks again I'll let you know how my crawling goes...

              the weekender coder

              Polar :)


              "'bonehead" <senmenospam@he re.org> wrote in message
              news:40E9F458.4 040401@here.org ...[color=blue]
              > Pedro Graca wrote:[color=green]
              > > I usually do (pseudo-code)
              > >
              > > <?php
              > > $query = "whatever";
              > > $result = mysql_query($qu ery)
              > > or die('Error in query [' . $query . ']. The error was: ' .[/color][/color]
              mysql_error());[color=blue][color=green]
              > > ?>
              > >
              > > Hint: is $_SESSION['username'] a string?[/color]
              >
              > Okay I'll hazard a guess on this one. I haven't tested this particular
              > solution, but I've occasionally run into similar problems.
              >
              > If Polar's $query is holding a string, is it possible that the php
              > expressions must be concatenated as they are in Pedro's example? For
              > instance, wouldn't you really need to do something like this:
              >
              > $query = "UPDATE Submission SET reader='".{$_SE SSION['username']}."',
              > date_processed= NOW(), accepted='Y' WHERE sub_id='".$row[0]."'";
              >
              > Also, wouldn't you want to do something like
              >
              > /*temporary error check line*/
              > echo $query;
              >
              > Just to make sure the query looks the way it's supposed to?
              >
              > Hope this helps.
              >[/color]


              Comment

              • Geoff Berrow

                #8
                Re: parse error in nested query - please help.

                I noticed that Message-ID: <40E9F458.40404 01@here.org> from 'bonehead
                contained the following:
                [color=blue]
                >/*temporary error check line*/
                >echo $query;
                >
                >Just to make sure the query looks the way it's supposed to?[/color]

                I usually do that and then paste the result into phpmyadmin That
                usually helps me find any SQL syntax errors.

                --
                Geoff Berrow (put thecat out to email)
                It's only Usenet, no one dies.
                My opinions, not the committee's, mine.
                Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                Comment

                • Pedro Graca

                  #9
                  Re: parse error in nested query - please help.

                  'bonehead wrote:[color=blue]
                  > Pedro Graca wrote:[color=green]
                  >> <?php
                  >> $query = "whatever";
                  >> $result = mysql_query($qu ery)
                  >> or die('Error in query [' . $query . ']. The error was: ' . mysql_error());
                  >> ?>[/color]
                  >
                  > If Polar's $query is holding a string, is it possible that the php
                  > expressions must be concatenated as they are in Pedro's example? For
                  > instance, wouldn't you really need to do something like this:
                  >
                  > $query = "UPDATE Submission SET reader='".{$_SE SSION['username']}."',
                  > date_processed= NOW(), accepted='Y' WHERE sub_id='".$row[0]."'";[/color]

                  No, not really. The string building of Polar's query is ok.
                  I don't like double quotes, but my die() expression could have been
                  written

                  die("Error in query [$query]. The error was: " . mysql_error());

                  [color=blue]
                  > Also, wouldn't you want to do something like
                  >
                  > /*temporary error check line*/
                  > echo $query;
                  >
                  > Just to make sure the query looks the way it's supposed to?[/color]

                  That is also a good idea.
                  The idea behind the die is to get the query itself written to the output
                  as long as the reason for failure. Suppose you have this query

                  UPDATE xyz SET id=8 WHERE id=2

                  and try to run it on a database that has no xyz table. The die() output
                  will be something like

                  Error in query [UPDATE xyz SET id=8 WHERE id=2]. The error
                  was: Table 'xyz' doesn't exist


                  --
                  USENET would be a better place if everybody read: | to email me: use |
                  http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
                  http://www.netmeister.org/news/learn2quote2.html | header, textonly |
                  http://www.expita.com/nomime.html | no attachments. |

                  Comment

                  Working...