All it takes is a new set of eyes.... and the most glaringly obvious mistake shall come to light.

(I got that one straight away too...)

    Oh come on. We've all done that one...

    or is it just me?

      Originally posted by The Chancer
      All it takes is a new set of eyes.... and the most glaringly obvious mistake shall come to light.

      Right. Now, my wife could care less about PHP, or computers in general; so, what I really need is some smart guy (i.e., new set of eyes) who'll work for dinner.... 😃 😃

        Here's an easy one that puzzled me for a while when I was writing a class:
        Say we have a class that handles FTP.
        This is part of some member function to upload:

        if ($this->getFtpMode($filename) == NULL) {
        	//file is invalid
        }
        else {
        	//upload file
        }

        getFtpMode() is a simplistic member function that returns FTP_ASCII, FTP_BINARY, or NULL depending on the file extension.
        dalecosp tries to upload a textfile, piersk.txt
        While is it always tagged as invalid?

          Well, as I'm an old PH[p]art that's not into OOP, can't say I'm sure, but likely a matter of operator precedence that set the entire expression to NULL prior to evaluating it?

          And, technically speaking, that's not a parse error, but a logic/programming one, otherwise known as PBKAC ... but I'm very guilty of those 😉

          One of the smart guys will get it if I'm wrong...

          Here's one that's all too common, I suppose; culled from some post on here that I thought about responding to, but didn't:

          <?php
          $auth = false;
          if(isset($_POST["login"])) {
             $user = $_POST["username"];
             $password = $_POST["password"];
             $cookie = $_POST["cookie"];
             }
          ob_start();
                  include("./root.txt");
                  $root = ob_get_contents();
          ob_end_clean();
          
          $file = file ("$root/data/members.txt");
          
          foreach ($file as $line) {
                  list($id, $userdata, $md5password)= explode ("|", $line);
                  if($user == $userdata and md5($password) == $md5password) {
                      $auth = true;
                      } else {
                  print("Incorrect username/password combination.");
                  }
          
          if ($auth = true)
              {
                  header("Set-Cookie: userid=$user; path=/");
                      if ($user == $userdata)
                          {
                          header("Set-Cookie: id=$id; path=/");
                                  {
                                  header("Set-Cookie: pass=$md5password; path=/");
           header("Location: <a href="http://" target="_blank">http://</a>".$HTTP_SERVER_VARS
          ['HTTP_HOST']."/forums/index.php");
                   print("Thanks.  You are now logged in as: ");
                  print("<b>{$user}</b> - <a href='../index.php'>Click ");
                  print(" here</a> to return to the forum index.");
                                  }
                          }
              }
          }
          ?>

          which yields ...

          Parse error: parse error in /www/phptests/thistest.html on line 31

          Of course, there's a couple other things I wouldn't do, either, I suppose....

            hmm... yes, it is technically a logic error.

              laserlight: not sure if this impacts your little code snippet or not... kind of a limited scope, but does $filename need to be $this->filename? I've forgotten the 'this->' on occasion, and it takes me too long to spot usually.

                Originally posted by dalecosp
                Well, as I'm an old PH[p]art that's not into OOP, can't say I'm sure, but likely a matter of operator precedence that set the entire expression to NULL prior to evaluating it?

                And, technically speaking, that's not a parse error, but a logic/programming one, otherwise known as PBKAC ... but I'm very guilty of those 😉

                One of the smart guys will get it if I'm wrong...

                Here's one that's all too common, I suppose; culled from some post on here that I thought about responding to, but didn't:

                <?php
                $auth = false;
                if(isset($_POST["login"])) {
                   $user = $_POST["username"];
                   $password = $_POST["password"];
                   $cookie = $_POST["cookie"];
                   }
                ob_start();
                        include("./root.txt");
                        $root = ob_get_contents();
                ob_end_clean();
                
                $file = file ("$root/data/members.txt");
                
                foreach ($file as $line) {
                        list($id, $userdata, $md5password)= explode ("|", $line);
                        if($user == $userdata and md5($password) == $md5password) {
                            $auth = true;
                            } else {
                        print("Incorrect username/password combination.");
                        }
                
                if ($auth = true)
                    {
                        header("Set-Cookie: userid=$user; path=/");
                            if ($user == $userdata)
                                {
                                header("Set-Cookie: id=$id; path=/");
                                        {
                                        header("Set-Cookie: pass=$md5password; path=/");
                 header("Location: <a href="http://" target="_blank">[url]http://[/url]</a>".$HTTP_SERVER_VARS
                ['HTTP_HOST']."/forums/index.php");
                         print("Thanks.  You are now logged in as: ");
                        print("<b>{$user}</b> - <a href='../index.php'>Click ");
                        print(" here</a> to return to the forum index.");
                                        }
                                }
                    }
                }
                ?>

                which yields ...

                Parse error: parse error in /www/phptests/thistest.html on line 31

                Of course, there's a couple other things I wouldn't do, either, I suppose.... [/B]

                Well, first thing I notice, is that in the target="" part of the link, the quotes are not escaped.

                  the quotes are not escaped...

                  Anything else? 😃

                    Originally posted by dalecosp
                    header("Location: <a href="http://" target="_blank">[url]http://[/url]</a>".$HTTP_SERVER_VARS
                    ['HTTP_HOST']."/forums/index.php");
                    Parse error: parse error in /www/phptests/thistest.html on line 31

                    I don't think the use of all those double quotes would make it very happy.

                    -Elizabeth

                      Originally posted by Elizabeth
                      I don't think the use of all those double quotes would make it very happy.

                      -Elizabeth

                      [edit]
                      LOL- guess I should actually, like, read the whole thread before posting 🙂
                      [/edit]

                        Looks like theres a lot of curly-brace mismatch.

                        Edit: looks like those unescaped quotes are due to the forum (note they double each time it's used) adding links or something when it shouldn't.

                          Well, I've got a few of you guys/gals thinking, anywho....

                          It's my belief that the URL in any header:Location call must be of the absolute URL format, and not include any a href HTML tags, so the basic thing I thought about it is that the newb who posted it needed to RTFM a bit, eh?

                          All of you found something wrong, though, so Yippee!! Have whatever you wish to drink and someone please post us the next round?

                          😃

                            🙁 im always too late! everyone's already said everything that's wrong basically..........:🙁🙁🙁 sob

                              Just so you can't say we don't like you around here, Moonglobe....

                              <?
                              if ($Moonglobe=="late") {
                                 echo "It's OK.....";
                              ?>

                              Can you find that one? 😃

                                YES i can see an error, though it wont generate one...........

                                i'm speaking of course of the '<?'. wont work for me 😃 /me loves xml

                                but thx 🙂

                                  and the most obvious being the if statement not being closed with a curly bracket. 😃

                                  Cgraz

                                    OK, then, CGraz, your turn...

                                    Moonglobe, you don't use short tags? Hmm, let's rethink this "be nice" idea... 😃

                                      alright dalecosp, here's one.

                                      <?
                                      
                                      $1animal = "dogs";
                                      $2animal = "cats";
                                      
                                      echo "I have 3 " . $1animal . " and 4 " . $2animal;
                                      
                                      ?>

                                      Cgraz