473,378 Members | 1,280 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,378 software developers and data experts.

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 22307
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: scoop_77 | last post by:
I'm looking for some software that would allow me to point to a folder in Windows Explorer, and have it output an html file with hyperlinks to all of the files within that folder and all of the...
2
by: gboissiere | last post by:
Hello 'contentEditable' gurus, The example code below uses contentEditable to let the user edit the <div> element directly in their browser. Works also using designMode for the document. ...
6
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would...
5
by: John Warner | last post by:
I have a wierd problem that I can't find any reference to in the knowledge base. I develop simple databases at the company where I work, and many of them are used by hundreds of employees. We all...
0
by: acconrad | last post by:
We're trying to make it such that you can change the color for hyperlinks in RichTextBox controls. Currently VS.NET '03 does not allow one to do this. We tried this -->...
1
by: Jason L James | last post by:
Hi all, I have datagrid with a column that is to contain hyperlinks to other documents. The is in the columns from a bound data source but I would like to format them as hyperlinks so that I...
4
by: Seefor | last post by:
Hi, I want my text hyperlinks to have a dotted border underneath, so I did this which works fine: a, a:link, a:visited, a:hover, a:active { color: #000; text-decoration: none;
1
by: Robin | last post by:
Hello! I'm having trouble with links and hyperlinks in MS Access 2003 - any help would be great! Question 1! The "insert hyperlink" icon opens a browser window, allows the user to browse...
1
by: Janna | last post by:
Hello tech savvy gurus! I hope someone can help me! THE PROBLEM: "Cannot open specified file" when I click on a hyperlink in an Access database when it is located on our server. THE...
1
by: vidhya17 | last post by:
I find that hyperlinks created and active in Microsoft Word are still looking like hyperlinks, but no longer active. That is to say when the Adobe Reader grasping hand mouse-pointer is over the link...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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...

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.