473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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_url 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_url. Any help
would be appreciated!
<?php if (defined($book_review_url)) echo "<a href=\"$book_review_url
\">Click here for reviews for $title on Amazon.com</a>"; ?>

Mar 9 '07 #1
9 1209
On 2007-03-09 17:03, fi************@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_url 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_url. Any help
would be appreciated!
<?php if (defined($book_review_url)) echo "<a href=\"$book_review_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_url exists and you
want to just check if it's not empty, use
if ($book_review_url != "")

If you don't know if the variable even exists, use
if (exists($book_review_url) && $book_review_url != "")
Mar 9 '07 #2
John C. Frickson wrote:
If you don't know if the variable even exists, use
if (exists($book_review_url) && $book_review_url != "")
exists() isn't mentioned anywhere in the PHP manual - I assume you mean isset()...

--cb
Mar 9 '07 #3
Message-ID: <55*************@mid.dfncis.defrom Christoph Burschka
contained the following:
>If you don't know if the variable even exists, use
if (exists($book_review_url) && $book_review_url != "")

exists() isn't mentioned anywhere in the PHP manual - I assume you mean isset()...
or you can just do

if (!empty( $book_review_url )){
,,,
}

--
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/
Mar 10 '07 #4
fi************@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_url 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_url. Any help
would be appreciated!
<?php if (defined($book_review_url)) echo "<a href=\"$book_review_url
\">Click here for reviews for $title on Amazon.com</a>"; ?>
if (ISSET($book_review_url) {}

or, depending,

if ($book_review_url) {}

Louise
Mar 10 '07 #5
<fi************@gmail.comwrote in message
news:11********************@64g2000cwx.googlegroup s.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_review_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_url . ">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
www.curvemeister.com/forum/
Mar 10 '07 #6
Rik
Mike Russell <RE*********@Curvemeister.comRE-MOVEwrote:
<fi************@gmail.comwrote in message
news:11********************@64g2000cwx.googlegroup s.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_review_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_url . ">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
Mar 10 '07 #7
Message-ID: <4F*****************@newssvr27.news.prodigy.netfro m Mike
Russell contained the following:
><?php if (defined($book_review_url)) echo "<a href=\"$book_review_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_url . ">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_url . '">Click here for reviews for
'.$title.' on Amazon.com</a>';

But being lazy I'd usually do

echo "<a href='$book_review_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/
Mar 10 '07 #8
Mike Russell wrote:
<fi************@gmail.comwrote in message
news:11********************@64g2000cwx.googlegroup s.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_review_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_url . ">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_url 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.
js*******@attglobal.net
==================
Mar 10 '07 #9
"Jerry Stuckle" <js*******@attglobal.netwrote in message
news:pY******************************@comcast.com. ..

[re correction of my correction]
Actually, the quotes need to be escaped. They are part of the HTML code.
$book_review_url 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
www.curvemeister.com/forum/
Mar 10 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: learningGuy | last post by:
Can someone tell me what is wrong with this simple code? I get an exception every time at the myFile.Open() line. I have included the code that I think is needed to for you to answer this below:...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
11
by: Alfonso Morra | last post by:
Hi, I am at the end of my tether now - after spending several days trying to figure how to do this. I have finally written a simple "proof of concept" program to test serializing a structure...
2
by: Phil Certain | last post by:
Hi, Relative newbie to .Net but experienced with classic ASP. I am trying to create a simple business object to contain commonly used functions. This is what I have done: 1 - Created a simple...
63
by: Jake Barnes | last post by:
In the course of my research I stumbled upon this article by Alex Russel and Tim Scarfe: http://www.developer-x.com/content/innerhtml/default.html The case is made that innerHTML should never...
11
by: frankie_85 | last post by:
Hi everyone, I just made a simple code which is part of my assignment but I can't figure it out what's wrong with it. (always give me error messages) What the code basically does is: a...
10
by: Enkidu | last post by:
Beginner question, sorry! I am using indexers to access an array of StringBuilders in an instance of a class: Getting: value = board1; Setting: board1 = value1 ;
6
by: Kid Programmer | last post by:
Hello guys. I have a question. What's wrong with my compiler. In a simple number averaging program in a GUI window have way into the project I compile the program and I get the following errors: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.