469,352 Members | 1,661 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

Hyperlinks in PHP anyone?

Hi i'm trying to write a piece of code which writes the message on
screen "access denied" telling the user he can't access this page
without logging in and then offering a hyperlink to the login page.

Like this:

if ($queryrows)
{
echo("Welcome to the birthdays page");
}
else
{
echo("Access denied<br>");
echo("<a href="index.php">click here to access the login page</a>");
}

//this code works perfect until I type in the line with the hyperlink (
beginning echo("<a href...)). PHP won't accept this code.

My question is how can i insert a hyperlink (or equivalent link) to
another page in the above if...else statement?

Sep 3 '05 #1
5 22046
On Sat, 03 Sep 2005 13:59:40 -0700, monomaniac21 wrote:
echo("<a href="index.php">click here to access the login page</a>");
}

//this code works perfect until I type in the line with the hyperlink (
beginning echo("<a href...)). PHP won't accept this code.


You may want to prefix the inner quotes with a backslash, like this:

echo("<a href=\"index.php\">click here to access the login page</a>");
or, you may want to use single quotes:
echo('<a href="index.php">click here to access the login page</a>');
--
http://www.mgogala.com

Sep 3 '05 #2
monomaniac21 wrote:
Hi i'm trying to write a piece of code which writes the message on
screen "access denied" telling the user he can't access this page
without logging in and then offering a hyperlink to the login page.

Like this:

if ($queryrows)
{
echo("Welcome to the birthdays page");
}
else
{
echo("Access denied<br>");
echo("<a href="index.php">click here to access the login page</a>");
}

//this code works perfect until I type in the line with the hyperlink (
beginning echo("<a href...)). PHP won't accept this code.

My question is how can i insert a hyperlink (or equivalent link) to
another page in the above if...else statement?


echo('<a href="index.php">click here to access the login page</a>');
^ ^

Or

echo("<a href=\"index.php\">click here to access the login page</a>");

Read up on using quotes in strings...

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Sep 3 '05 #3
monomaniac21 wrote:
echo("<a href="index.php">click here to access the login page</a>"); //this code works perfect until I type in the line with the hyperlink (
beginning echo("<a href...)). PHP won't accept this code.
The problem is the above line. If you enclose the string in double
quotes you can not use double quotes inside the string without escaping
them because they end the string.

PHP thinks that your string is "<a href=" and expects either a comma and
another string to output or the closing bracket and a semicolon,
according to the echo syntax, but gets index.php">... instead.
My question is how can i insert a hyperlink (or equivalent link) to
another page in the above if...else statement?


You are doing it the right way, basically. You just have to watch how
you enclose strings.

Read the section in the manual, which explains that really well:
http://www.php.net/manual/en/language.types.string.php

Bye!
Sep 3 '05 #4
monomaniac21 wrote:
Hi i'm trying to write a piece of code which writes the message on
screen "access denied" telling the user he can't access this page
without logging in and then offering a hyperlink to the login page.

Like this:

if ($queryrows)
{
echo("Welcome to the birthdays page");
}
else
{
echo("Access denied<br>");
echo("<a href="index.php">click here to access the login page</a>");
}

//this code works perfect until I type in the line with the hyperlink
( beginning echo("<a href...)). PHP won't accept this code.

My question is how can i insert a hyperlink (or equivalent link) to
another page in the above if...else statement?

I always use single quotes first. Having a rule like that make it easy.
Often you will have html between your quotes (e.g. $s = '<a
href="..."></a>';). In HTML, you use double-quotes most of time, so it
works out perfectly. Then when you have the occasional javascript line, use
the escape character \

e.g.
$s = '
<a href="..." onmouseover="rollover(\'image.jpg\')"></a>';

Easy.

BTW, I dont think you need the brackets wtih echo

try

echo 'hello world';

- Nicolaas
Sep 3 '05 #5
Thanks guys you have fixed my problem.

Sep 4 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by John Warner | last post: by
1 post views Thread by Jason L James | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.