What is wrong with this php line?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Klen
    • Aug 2006
    • 32235

    #1

    What is wrong with this php line?

    I getting error Undefined variable: cat in and i have no idea why.This is line which makes that problem:
    PHP Code:
    echo "<td valign='top'><p align='center'><a href='girls/$rec->dirname/$rec->dirname.html'><img title='$cat $rec->name Gallery' src='Models/$rec->dirname/1.jpg' alt='$cat $rec->name Gallery' width='150' height='200' border='1' /><br>$cat $rec->name</a></p></td>"; 
    
    Any idea what is wrong ?
  • mikesouth
    Confirmed User
    • Jun 2003
    • 6334

    #2
    yup you are using a reserved word as a variable cat is a reserved word in UNIX
    Mike South

    It's No wonder I took up drugs and alcohol, it's the only way I could dumb myself down enough to cope with the morons in this biz.

    Comment

    • borked
      Totally Borked
      • Feb 2005
      • 6284

      #3
      $cat doesn't look to be defined (ie has never been called/assigned before) and you are running php with E_ALL

      Also, to give the parser an easier time, add braces around your vars when inside double quotes if you absolutely want to have them inside the double quotes

      ie

      echo "<td valign='top'><p align='center'><a href='girls/{$rec->dirname}/{$rec->dirname}.html'><img title='{$cat} {$rec->name} Gallery' src='Models/{$rec->dirname}/1.jpg' alt='{$cat} {$rec->name} Gallery' width='150' height='200' border='1' /><br>{$cat} {$rec->name}</a></p></td>";


      for parser speed inside/outside quotes, have a look at
      http://riyono.com/archives/2004/09/3...p-application/

      For coding work - hit me up on andy // borkedcoder // com
      (consider figuring out the email as test #1)



      All models are wrong, but some are useful. George E.P. Box. p202

      Comment

      • G-Rotica
        Confirmed User
        • Aug 2005
        • 4258

        #4
        Yea, your code is all red and hard to read.

        Comment

        • Klen
          • Aug 2006
          • 32235

          #5
          Ok here is clean copy pastE:
          echo "<td valign='top'><p align='center'><a href='girls/$rec->dirname/$rec->dirname.html'><img title='$cat $rec->name Gallery' src='Models/$rec->dirname/1.jpg' alt='$cat $rec->name Gallery' width='150' height='200' border='1' /><br>$cat $rec->name</a></p></td>";

          Comment

          • borked
            Totally Borked
            • Feb 2005
            • 6284

            #6
            like I said, look in your php.ini for what your error settings are - they are probably E_ALL. Set them lower to remove the 'strict' coding messages showing.

            For coding work - hit me up on andy // borkedcoder // com
            (consider figuring out the email as test #1)



            All models are wrong, but some are useful. George E.P. Box. p202

            Comment

            • k0nr4d
              Confirmed User
              • Aug 2006
              • 9231

              #7
              echo "<td valign='top'><p align='center'><a href='girls/".$rec->dirname."/".$rec->dirname.".html'><img title='".$cat." ".$rec->name." Gallery' src='Models/".$rec->dirname."/1.jpg' alt='".$cat." ".$rec->name." Gallery' width='150' height='200' border='1' /><br>".$cat." ".$rec->name."</a></p></td>";

              you can set "php_flag display_errors off" in htaccess to solve the warning
              Last edited by k0nr4d; 06-10-2008, 10:33 AM.
              Mechanical Bunny Media
              Mechbunny Tube Script | Mechbunny Webcam Aggregator Script | Custom Web Development

              Comment

              • tranza
                ICQ: 197-556-237
                • Jun 2003
                • 57559

                #8
                Originally posted by G-Rotica
                Yea, your code is all red and hard to read.
                I second that.
                I'm just a newbie.

                Comment

                • Klen
                  • Aug 2006
                  • 32235

                  #9
                  php_flag display_errors off in htaccess works.I wonder is that only solution.

                  Comment

                  • borked
                    Totally Borked
                    • Feb 2005
                    • 6284

                    #10
                    Originally posted by KlenTelaris
                    php_flag display_errors off in htaccess works.I wonder is that only solution.
                    no, the other solution is to declare your variables before using them.
                    So, befre tht echo statement, write:
                    $cat = '';

                    and then your error will go away.

                    strict or not-so-strict. The choice is yours

                    For coding work - hit me up on andy // borkedcoder // com
                    (consider figuring out the email as test #1)



                    All models are wrong, but some are useful. George E.P. Box. p202

                    Comment

                    • GrouchyAdmin
                      Now choke yourself!
                      • Apr 2006
                      • 12085

                      #11
                      Originally posted by KlenTelaris
                      php_flag display_errors off in htaccess works.I wonder is that only solution.
                      Actually, the other solution is to learn what you're doing before you try to do it.

                      Comment

                      • Iron Fist
                        Too lazy to set a custom title
                        • Dec 2006
                        • 23400

                        #12
                        My brain is exploding.
                        i like waffles

                        Comment

                        • brandonstills
                          Confirmed User
                          • Dec 2007
                          • 1964

                          #13
                          Originally posted by borked
                          Also, to give the parser an easier time, add braces around your vars when inside double quotes if you absolutely want to have them inside the double quotes

                          ie

                          echo "<td valign='top'><p align='center'><a href='girls/{$rec->dirname}/{$rec->dirname}.html'><img title='{$cat} {$rec->name} Gallery' src='Models/{$rec->dirname}/1.jpg' alt='{$cat} {$rec->name} Gallery' width='150' height='200' border='1' /><br>{$cat} {$rec->name}</a></p></td>";


                          for parser speed inside/outside quotes, have a look at
                          http://riyono.com/archives/2004/09/3...p-application/
                          Who cares about giving the parser an easier time? It exists to serve the programmer. I'm tired of all these people bitching about how PHP double quotes are slow. Using single quotes with the '.' operator maybe be faster but ask yourself this. By how much? Ok, even if it is 10 times faster how long do you think that translates to in actual time. Fractions of a nano second. It would have to be deep in an inner loop that is called 100,000+ times before the user would even notice a _slight_ difference. What's more important, having readable code, or shaving an additional 0.000000000001 seconds off the page loading time?

                          "Premature optimization is the root of all evil."

                          Now, I'm not one to say you should never optimize. I used to expand assembly code to half a dozen instructions when I could do it with 1 because the MUL instruction used to be really slow on the early x86 platforms. But only inside some kind of loop where it would mean a noticable difference to the user. There's a time and place for optimization but don't make your code more unreadable needlessly.

                          Brandon Stills
                          Industry and programming veteran
                          [email protected] | skype: brandonstills | ICQ #495-171-318

                          Comment

                          Working...