What's wrong with this simple line of code?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fishmonger1972@gmail.com

    What's wrong with this simple line of code?

    I'm a librarian trying to put a finishing touch on an online materials
    catalog. The line below seems to do nothing in my program.. And I
    don't get any error messages. So, I'm very perplexed because it
    doesn't work as I'd like.

    I'm trying to see if $book_review_ur l is defined.. then if it is I
    want it to make 'Click here for reviews for $title' to be hyperlinked
    by the url that is in the database in $book_review_ur l. Any help
    would be appreciated!


    <?php if (defined($book_ review_url)) echo "<a href=\"$book_re view_url
    \">Click here for reviews for $title on Amazon.com</a>"; ?>

  • John C. Frickson

    #2
    Re: What's wrong with this simple line of code?

    On 2007-03-09 17:03, fishmonger1972@ gmail.com wrote:
    I'm a librarian trying to put a finishing touch on an online materials
    catalog. The line below seems to do nothing in my program.. And I
    don't get any error messages. So, I'm very perplexed because it
    doesn't work as I'd like.
    >
    I'm trying to see if $book_review_ur l is defined.. then if it is I
    want it to make 'Click here for reviews for $title' to be hyperlinked
    by the url that is in the database in $book_review_ur l. Any help
    would be appreciated!
    >
    >
    <?php if (defined($book_ review_url)) echo "<a href=\"$book_re view_url
    \">Click here for reviews for $title on Amazon.com</a>"; ?>
    defined() only works for constants, not variables.

    If you know that the variable $book_review_ur l exists and you
    want to just check if it's not empty, use
    if ($book_review_u rl != "")

    If you don't know if the variable even exists, use
    if (exists($book_r eview_url) && $book_review_ur l != "")

    Comment

    • Christoph Burschka

      #3
      Re: What's wrong with this simple line of code?

      John C. Frickson wrote:
      If you don't know if the variable even exists, use
      if (exists($book_r eview_url) && $book_review_ur l != "")
      exists() isn't mentioned anywhere in the PHP manual - I assume you mean isset()...

      --cb

      Comment

      • Geoff Berrow

        #4
        Re: What's wrong with this simple line of code?

        Message-ID: <55e9srF251ueiU 1@mid.dfncis.de from Christoph Burschka
        contained the following:
        >If you don't know if the variable even exists, use
        > if (exists($book_r eview_url) && $book_review_ur l != "")
        >
        >exists() isn't mentioned anywhere in the PHP manual - I assume you mean isset()...
        or you can just do

        if (!empty( $book_review_ur l )){
        ,,,
        }

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

        • boclair

          #5
          Re: What's wrong with this simple line of code?

          fishmonger1972@ gmail.com wrote:
          I'm a librarian trying to put a finishing touch on an online materials
          catalog. The line below seems to do nothing in my program.. And I
          don't get any error messages. So, I'm very perplexed because it
          doesn't work as I'd like.
          >
          I'm trying to see if $book_review_ur l is defined.. then if it is I
          want it to make 'Click here for reviews for $title' to be hyperlinked
          by the url that is in the database in $book_review_ur l. Any help
          would be appreciated!
          >
          >
          <?php if (defined($book_ review_url)) echo "<a href=\"$book_re view_url
          \">Click here for reviews for $title on Amazon.com</a>"; ?>
          >
          if (ISSET($book_re view_url) {}

          or, depending,

          if ($book_review_u rl) {}

          Louise

          Comment

          • Mike Russell

            #6
            Re: What's wrong with this simple line of code?

            <fishmonger1972 @gmail.comwrote in message
            news:1173481411 .332250.5390@64 g2000cwx.google groups.com...
            I'm a librarian trying to put a finishing touch on an online materials
            catalog. The line below seems to do nothing in my program.. And I
            ....
            <?php if (defined($book_ review_url)) echo "<a href=\"$book_re view_url
            \">Click here for reviews for $title on Amazon.com</a>"; ?>
            Others have mentioned use of isset(). Two other errors are that you should
            not escape the quotes in this situation, and use . to concatenate strings:

            echo "<a href=" . $book_review_ur l . ">Click here for reviews for $title on
            Amazon.com</a>"
            (watch for line breaks in this posted message)

            There are some things you can do to make writing code like this easier. You
            can use an IDE with a built-in syntax checker to find errors as you type
            them in, instead of later - eclipse is my current favorite, and there are
            other excellent ones, or use php -l to do a quick syntax check. Also, copy
            code that others have written, rather than create it yourself from scratch.
            --
            Mike Russell



            Comment

            • Rik

              #7
              Re: What's wrong with this simple line of code?

              Mike Russell <RE-MOVEmike@Curvem eister.comRE-MOVEwrote:
              <fishmonger1972 @gmail.comwrote in message
              news:1173481411 .332250.5390@64 g2000cwx.google groups.com...
              >I'm a librarian trying to put a finishing touch on an online materials
              >catalog. The line below seems to do nothing in my program.. And I
              ...
              ><?php if (defined($book_ review_url)) echo "<a href=\"$book_re view_url
              >\">Click here for reviews for $title on Amazon.com</a>"; ?>
              >
              Others have mentioned use of isset(). Two other errors are that you
              should
              not escape the quotes in this situation, and use . to concatenate
              strings:
              >
              echo "<a href=" . $book_review_ur l . ">Click here for reviews for $title
              on
              Amazon.com</a>"
              (watch for line breaks in this posted message)
              >
              There are some things you can do to make writing code like this easier..
              You
              can use an IDE with a built-in syntax checker to find errors as you type
              them in, instead of later - eclipse is my current favorite, and there are
              other excellent ones, or use php -l to do a quick syntax check.
              Check, I'm using UltraEdit myself, and a quick Ctrl+Shift+1 really helps
              in syntax checking (And configurable tools rool. I do not need expensive
              packages as long as can use any custom tool I desire :-)
              Also, copy code that others have written, rather than create it yourself
              from scratch.
              Ammendment: you _do_ have to understand the code others have written IMHO.
              --
              Rik Wasmus
              Posted on Usenet, not any forum you might see this in.
              Ask Smart Questions: http://tinyurl.com/anel

              Comment

              • Geoff Berrow

                #8
                Re: What's wrong with this simple line of code?

                Message-ID: <4FvIh.2507$FG1 .2028@newssvr27 .news.prodigy.n etfrom Mike
                Russell contained the following:
                ><?php if (defined($book_ review_url)) echo "<a href=\"$book_re view_url
                >\">Click here for reviews for $title on Amazon.com</a>"; ?>
                >
                >Others have mentioned use of isset(). Two other errors are that you should
                >not escape the quotes in this situation, and use . to concatenate strings:
                >
                >echo "<a href=" . $book_review_ur l . ">Click here for reviews for $title on
                >Amazon.com</a>"
                >(watch for line breaks in this posted message)
                Umm...ITYM
                echo '<a href="' . $book_review_ur l . '">Click here for reviews for
                '.$title.' on Amazon.com</a>';

                But being lazy I'd usually do

                echo "<a href='$book_rev iew_url '>Click here for reviews for $title on
                Amazon.com</a>";

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

                • Jerry Stuckle

                  #9
                  Re: What's wrong with this simple line of code?

                  Mike Russell wrote:
                  <fishmonger1972 @gmail.comwrote in message
                  news:1173481411 .332250.5390@64 g2000cwx.google groups.com...
                  >I'm a librarian trying to put a finishing touch on an online materials
                  >catalog. The line below seems to do nothing in my program.. And I
                  ...
                  ><?php if (defined($book_ review_url)) echo "<a href=\"$book_re view_url
                  >\">Click here for reviews for $title on Amazon.com</a>"; ?>
                  >
                  Others have mentioned use of isset(). Two other errors are that you should
                  not escape the quotes in this situation, and use . to concatenate strings:
                  >
                  echo "<a href=" . $book_review_ur l . ">Click here for reviews for $title on
                  Amazon.com</a>"
                  (watch for line breaks in this posted message)
                  >
                  Actually, the quotes need to be escaped. They are part of the HTML
                  code. $book_review_ur l will still be expanded. And he isn't doing
                  string concatenation. So no '.' is required.

                  The result should look similar to:

                  <a href="http://www.example.com/book_reviews">. ..


                  There are some things you can do to make writing code like this easier. You
                  can use an IDE with a built-in syntax checker to find errors as you type
                  them in, instead of later - eclipse is my current favorite, and there are
                  other excellent ones, or use php -l to do a quick syntax check. Also, copy
                  code that others have written, rather than create it yourself from scratch.
                  No syntax errors. Just a problem with not using isset().

                  --
                  =============== ===
                  Remove the "x" from my email address
                  Jerry Stuckle
                  JDS Computer Training Corp.
                  jstucklex@attgl obal.net
                  =============== ===

                  Comment

                  • Mike Russell

                    #10
                    Re: What's wrong with this simple line of code?

                    "Jerry Stuckle" <jstucklex@attg lobal.netwrote in message
                    news:pYidnSYSPv A5JG_YnZ2dnUVZ_ vfinZ2d@comcast .com...

                    [re correction of my correction]
                    Actually, the quotes need to be escaped. They are part of the HTML code.
                    $book_review_ur l will still be expanded. And he isn't doing string
                    concatenation. So no '.' is required.
                    >
                    The result should look similar to:
                    >
                    <a href="http://www.example.com/book_reviews">. ..
                    Right you are Jerry. I stand corrected. This will save me some typing in
                    the future. :-)
                    --
                    Mike Russell



                    Comment

                    Working...