unexpected T_IF error

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

    #1

    unexpected T_IF error

    ok, I am totally new to php and come from an asp background.

    I basically want to do an If > then > else > end if statement:


    my page is:

    <?php require_once('C onnections/carresa.php'); ?>
    <?php
    $DateTime = date("Y/n/j");
    $IP = $_SERVER["REMOTE_ADD R"];

    mysql_select_db ($database_carr esa, $carresa);
    $query_rs = "SELECT count(Hit_DateT ime) as mycount FROM unique_ip WHERE
    Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
    $rs = mysql_query($qu ery_rs, $carresa) or die(mysql_error ());
    $row_rs = mysql_fetch_ass oc($rs);
    $totalRows_rs = mysql_num_rows( $rs);


    print "<span class=white11>" . $query_rs . "<br>IP: " .
    $_SERVER["REMOTE_ADD R"] . "<br>Date Time: " . $DateTime . "<br>Count: " .
    $row_rs['mycount'] . "</span>"


    //at this point I want to say IF row_rs['mycount']== 0 THEN PRINT WELCOME ON
    THE PAGE
    if ($row_rs['mycount']=='0'){
    print "welcome";
    }
    ?>


    The page errors on line 17 which is the if line.

    Any ideas ???

    thanks
    James Campbell


  • Jon Kraft

    #2
    Re: unexpected T_IF error

    "James Campbell" <james@stutters ystems.com> wrote:

    [color=blue]
    > print "<span class=white11>" . $query_rs . "<br>IP: " .
    > $_SERVER["REMOTE_ADD R"] . "<br>Date Time: " . $DateTime . "<br>Count:
    > " . $row_rs['mycount'] . "</span>"
    >
    >
    > //at this point I want to say IF row_rs['mycount']== 0 THEN PRINT
    > WELCOME ON THE PAGE
    > if ($row_rs['mycount']=='0'){
    > print "welcome";
    > }
    > ?>
    >
    >
    > The page errors on line 17 which is the if line.[/color]

    You missed a semicolon in the "print" line before the if statement.

    JOn

    Comment

    • Geoff Berrow

      #3
      Re: unexpected T_IF error

      I noticed that Message-ID: <Xns944C5F2C7EC F7jonjonuxcouk@ 130.133.1.4>
      from Jon Kraft contained the following:
      [color=blue][color=green]
      >> if ($row_rs['mycount']=='0'){
      >> print "welcome";
      >> }
      >> ?>
      >>
      >>
      >> The page errors on line 17 which is the if line.[/color]
      >
      >You missed a semicolon in the "print" line before the if statement.[/color]
      Does it matter that the '0' is in single quotes?

      --
      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

      • Jon Kraft

        #4
        Re: unexpected T_IF error

        Geoff Berrow <blthecat@ckdog .co.uk> wrote:
        [color=blue]
        > I noticed that Message-ID: <Xns944C5F2C7EC F7jonjonuxcouk@ 130.133.1.4>
        > from Jon Kraft contained the following:
        >[color=green][color=darkred]
        >>> if ($row_rs['mycount']=='0'){
        >>> print "welcome";
        >>> }
        >>> ?>
        >>>
        >>>
        >>> The page errors on line 17 which is the if line.[/color]
        >>
        >>You missed a semicolon in the "print" line before the if statement.[/color][/color]
        [color=blue]
        > Does it matter that the '0' is in single quotes?[/color]

        Not really, it wouldn't throw an error for once and PHP's internal type
        conversion would render that statement true if the number of rows returned
        would be 0.
        However, if ($row_rs['mycount']===0) would be the better solution.

        JOn

        Comment

        • James Campbell

          #5
          Re: unexpected T_IF error

          Geoff, Jon,

          Thanks for replying, I have tried both your suggestions, but still get the
          error. My current code is:

          if ($row_rs['mycount']===0){
          print "welcome"
          }

          If I however put the code in like this:

          <?php if ($row_rs['icount']=="0"){ ?>
          <br>ddddd
          <?php } ?>

          The page works.

          Any ideas ??

          Thanks

          James

          "Jon Kraft" <jon@jonux.co.u k> wrote in message
          news:Xns944C815 804289jonjonuxc ouk@130.133.1.4 ...[color=blue]
          > Geoff Berrow <blthecat@ckdog .co.uk> wrote:
          >[color=green]
          > > I noticed that Message-ID: <Xns944C5F2C7EC F7jonjonuxcouk@ 130.133.1.4>
          > > from Jon Kraft contained the following:
          > >[color=darkred]
          > >>> if ($row_rs['mycount']=='0'){
          > >>> print "welcome";
          > >>> }
          > >>> ?>
          > >>>
          > >>>
          > >>> The page errors on line 17 which is the if line.
          > >>
          > >>You missed a semicolon in the "print" line before the if statement.[/color][/color]
          >[color=green]
          > > Does it matter that the '0' is in single quotes?[/color]
          >
          > Not really, it wouldn't throw an error for once and PHP's internal type
          > conversion would render that statement true if the number of rows returned
          > would be 0.
          > However, if ($row_rs['mycount']===0) would be the better solution.
          >
          > JOn[/color]


          Comment

          • Jon Kraft

            #6
            Re: unexpected T_IF error

            "James Campbell" <james@stutters ystems.com> wrote:
            [color=blue]
            > Thanks for replying, I have tried both your suggestions, but still get
            > the error. My current code is:
            >
            > if ($row_rs['mycount']===0){
            > print "welcome"
            > }
            >
            > If I however put the code in like this:
            >
            > <?php if ($row_rs['icount']=="0"){ ?>
            > <br>ddddd
            > <?php } ?>
            >
            > The page works.
            >
            > Any ideas ??[/color]

            Hi James,

            That doesn't make sense ... but you are using two different keys in your
            example: 'mycount' and 'icount'. Could you post the complete code again?

            JOn

            Comment

            • Geoff Berrow

              #7
              Re: unexpected T_IF error

              I noticed that Message-ID:
              <oQmBb.32421$LI 6.2018@news-binary.blueyond er.co.uk> from James Campbell
              contained the following:
              [color=blue]
              >if ($row_rs['mycount']===0){
              >print "welcome"
              >}[/color]

              Have you tried
              print "welcome";



              --
              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

              • James Campbell

                #8
                Re: unexpected T_IF error

                Jon,

                Sorry yes I saw that a few minutes ago (doh!)

                The code that doesn't work is:

                <?php require_once('C onnections/carresa.php'); ?>
                <?php
                $DateTime = date("Y/n/j");
                $IP = $_SERVER["REMOTE_ADD R"];

                mysql_select_db ($database_carr esa, $carresa);
                $query_rs = "SELECT count(Hit_DateT ime) as mycount FROM unique_ip WHERE
                Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
                $rs = mysql_query($qu ery_rs, $carresa) or die(mysql_error ());
                $row_rs = mysql_fetch_ass oc($rs);
                $totalRows_rs = mysql_num_rows( $rs);


                print "<span class=white11>" . $query_rs . "<br>IP: " .
                $_SERVER["REMOTE_ADD R"] . "<br>Date Time: " . $DateTime . "<br>Count: " .
                $row_rs['mycount'] . "</span>"


                //at this point I want to say IF row_rs['mycount']== 0 THEN PRINT WELCOME ON
                THE PAGE
                if ($row_rs['mycount']===0){
                print "welcome"
                }


                ?>

                The code that does work is:

                <?php require_once('C onnections/carresa.php'); ?>
                <?php
                $DateTime = date("Y/n/j");
                $IP = $_SERVER["REMOTE_ADD R"];

                mysql_select_db ($database_carr esa, $carresa);
                $query_rs = "SELECT count(Hit_DateT ime) as mycount FROM unique_ip WHERE
                Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
                $rs = mysql_query($qu ery_rs, $carresa) or die(mysql_error ());
                $row_rs = mysql_fetch_ass oc($rs);
                $totalRows_rs = mysql_num_rows( $rs);


                print "<span class=white11>" . $query_rs . "<br>IP: " .
                $_SERVER["REMOTE_ADD R"] . "<br>Date Time: " . $DateTime . "<br>Count: " .
                $row_rs['mycount'] . "</span>"


                //at this point I want to say IF row_rs['mycount']== 0 THEN PRINT WELCOME ON
                THE PAGE
                //if ($row_rs['mycount']===0){
                //print "welcome"
                //}


                ?>

                <?php if ($row_rs['mycount']=="0"){ ?>
                <br>ddddd
                <?php } ?>


                Seems strange how I can't include the bottom bit of code in the main chunk
                of code ??

                Cheers
                James










                "Jon Kraft" <jon@jonux.co.u k> wrote in message
                news:Xns944CA9C B2A30Bjonjonuxc ouk@130.133.1.4 ...[color=blue]
                > "James Campbell" <james@stutters ystems.com> wrote:
                >[color=green]
                > > Thanks for replying, I have tried both your suggestions, but still get
                > > the error. My current code is:
                > >
                > > if ($row_rs['mycount']===0){
                > > print "welcome"
                > > }
                > >
                > > If I however put the code in like this:
                > >
                > > <?php if ($row_rs['icount']=="0"){ ?>
                > > <br>ddddd
                > > <?php } ?>
                > >
                > > The page works.
                > >
                > > Any ideas ??[/color]
                >
                > Hi James,
                >
                > That doesn't make sense ... but you are using two different keys in your
                > example: 'mycount' and 'icount'. Could you post the complete code again?
                >
                > JOn[/color]


                Comment

                • Jon Kraft

                  #9
                  Re: unexpected T_IF error

                  "James Campbell" <james@stutters ystems.com> wrote:
                  [color=blue]
                  > Jon,
                  >
                  > Sorry yes I saw that a few minutes ago (doh!)
                  >
                  > The code that doesn't work is:
                  >
                  > <?php require_once('C onnections/carresa.php'); ?>
                  > <?php
                  > $DateTime = date("Y/n/j");
                  > $IP = $_SERVER["REMOTE_ADD R"];
                  >
                  > mysql_select_db ($database_carr esa, $carresa);
                  > $query_rs = "SELECT count(Hit_DateT ime) as mycount FROM unique_ip
                  > WHERE Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
                  > $rs = mysql_query($qu ery_rs, $carresa) or die(mysql_error ());
                  > $row_rs = mysql_fetch_ass oc($rs);
                  > $totalRows_rs = mysql_num_rows( $rs);
                  >
                  >
                  > print "<span class=white11>" . $query_rs . "<br>IP: " .
                  > $_SERVER["REMOTE_ADD R"] . "<br>Date Time: " . $DateTime . "<br>Count:
                  > " . $row_rs['mycount'] . "</span>"[/color]

                  Hi James,

                  Did you read my first post? :)

                  You missed a semicolon to end the above line!

                  JOn

                  Comment

                  • James Campbell

                    #10
                    Re: unexpected T_IF error

                    Jon,

                    You are the man !!!!!

                    Excellent, thank you !

                    If you ever need and ASP code, just drop me an email.

                    Regards
                    James

                    "Jon Kraft" <jon@jonux.co.u k> wrote in message
                    news:Xns944CB9D D6B31Bjonjonuxc ouk@130.133.1.4 ...[color=blue]
                    > "James Campbell" <james@stutters ystems.com> wrote:
                    >[color=green]
                    > > Jon,
                    > >
                    > > Sorry yes I saw that a few minutes ago (doh!)
                    > >
                    > > The code that doesn't work is:
                    > >
                    > > <?php require_once('C onnections/carresa.php'); ?>
                    > > <?php
                    > > $DateTime = date("Y/n/j");
                    > > $IP = $_SERVER["REMOTE_ADD R"];
                    > >
                    > > mysql_select_db ($database_carr esa, $carresa);
                    > > $query_rs = "SELECT count(Hit_DateT ime) as mycount FROM unique_ip
                    > > WHERE Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
                    > > $rs = mysql_query($qu ery_rs, $carresa) or die(mysql_error ());
                    > > $row_rs = mysql_fetch_ass oc($rs);
                    > > $totalRows_rs = mysql_num_rows( $rs);
                    > >
                    > >
                    > > print "<span class=white11>" . $query_rs . "<br>IP: " .
                    > > $_SERVER["REMOTE_ADD R"] . "<br>Date Time: " . $DateTime . "<br>Count:
                    > > " . $row_rs['mycount'] . "</span>"[/color]
                    >
                    > Hi James,
                    >
                    > Did you read my first post? :)
                    >
                    > You missed a semicolon to end the above line!
                    >
                    > JOn[/color]


                    Comment

                    • Shawn Wilson

                      #11
                      Re: unexpected T_IF error

                      James Campbell wrote:[color=blue]
                      >
                      > ok, I am totally new to php and come from an asp background.
                      >
                      > I basically want to do an If > then > else > end if statement:
                      >
                      > my page is:
                      >
                      > <?php require_once('C onnections/carresa.php'); ?>
                      > <?php
                      > $DateTime = date("Y/n/j");
                      > $IP = $_SERVER["REMOTE_ADD R"];
                      >
                      > mysql_select_db ($database_carr esa, $carresa);
                      > $query_rs = "SELECT count(Hit_DateT ime) as mycount FROM unique_ip WHERE
                      > Hit_IP = '$IP' and hit_datetime = '#$DateTime#'";
                      > $rs = mysql_query($qu ery_rs, $carresa) or die(mysql_error ());
                      > $row_rs = mysql_fetch_ass oc($rs);
                      > $totalRows_rs = mysql_num_rows( $rs);
                      >
                      > print "<span class=white11>" . $query_rs . "<br>IP: " .
                      > $_SERVER["REMOTE_ADD R"] . "<br>Date Time: " . $DateTime . "<br>Count: " .
                      > $row_rs['mycount'] . "</span>"
                      >
                      > //at this point I want to say IF row_rs['mycount']== 0 THEN PRINT WELCOME ON
                      > THE PAGE
                      > if ($row_rs['mycount']=='0'){
                      > print "welcome";
                      > }
                      > ?>
                      >
                      > The page errors on line 17 which is the if line.[/color]

                      Often, the error will be on the line prior to the one PHP reports. You didn't
                      end your print statement with a ";". The T_IF is unexpected because it
                      shouldn't be in the middle of a print statment.

                      Regards,
                      Shawn
                      --
                      Shawn Wilson
                      shawn@glassgian t.com

                      Comment

                      Working...