473,395 Members | 1,496 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.

displaying html code using the echo command?

Hello **newbie alert** <-- that's me btw, but you might have guessed
that by my topic title.

I have an html page that submits a name and email address by a form to
a page called preview.php

I'd like to do some basic validation on the credentials subbitted via
the form, and if they pass then send the credentials via email and
display the rest of the page (which will have links to download some
promotional tunes from my friends record label)

If the validation fails I'd like to display an alternative version of
the page telling the user to go back and fill in the form properly.

Can I do this by simply enclosing some html code in an echo statement?

for example

echo "<div id="success">Thanks, here are the links you are looking
for....</div>";

I'm guessing I might have to escape the extra quotation marks, because
it wouldn't parse the line when I just tried it.

Anyway.. Am I barking up the wrong tree completely?

Thanks in advance

Doug.

Apr 3 '07 #1
3 5765
On Apr 3, 1:22 pm, "Doug (dtism)" <d...@dtism.co.ukwrote:
Hello **newbie alert** <-- that's me btw, but you might have guessed
that by my topic title.

I have an html page that submits a name and email address by a form to
a page called preview.php

I'd like to do some basic validation on the credentials subbitted via
the form, and if they pass then send the credentials via email and
display the rest of the page (which will have links to download some
promotional tunes from my friends record label)

If the validation fails I'd like to display an alternative version of
the page telling the user to go back and fill in the form properly.

Can I do this by simply enclosing some html code in an echo statement?

for example

echo "<div id="success">Thanks, here are the links you are looking
for....</div>";

I'm guessing I might have to escape the extra quotation marks, because
it wouldn't parse the line when I just tried it.

Anyway.. Am I barking up the wrong tree completely?

Thanks in advance

Doug.
Not really completely, but avoid echoing as much as possible. You
might try doing it this way:
<?php
if ( ... ) {
?>
<div id="success">
Thanks, here are the links you are looking for...
</div>
<?php
}
?>

Better yet, you could use smarty or some other templating system, so
you don't at all mix your php and html, but maybe you better practice
like this for now, until you learn more.

Cheers,
Darko

Apr 3 '07 #2
Doug (dtism) wrote:
Hello **newbie alert** <-- that's me btw, but you might have guessed
that by my topic title.

I have an html page that submits a name and email address by a form to
a page called preview.php

I'd like to do some basic validation on the credentials subbitted via
the form, and if they pass then send the credentials via email and
display the rest of the page (which will have links to download some
promotional tunes from my friends record label)

If the validation fails I'd like to display an alternative version of
the page telling the user to go back and fill in the form properly.

Can I do this by simply enclosing some html code in an echo statement?
Yes, can be done, but doesn't it make more sense to send the visitor back to
the original form?
$succes = ...your test goes here...
if (!$succes) {
// send back to page with loginform
header("Location: loginform.php?result=".urlencode('bad login.'));
exit;
}

// just continue here with page with samples
You can easily get the 'result' in your loginpage to display like this:
<?php
if (isset($_GET["result"])){
echo $_GET["result"];
}
?>
That way your visitor understands what is going on.
>
for example

echo "<div id="success">Thanks, here are the links you are looking
for....</div>";

I'm guessing I might have to escape the extra quotation marks, because
it wouldn't parse the line when I just tried it.
excactly.
Also, consider less usage of echo. It makes your life unneeded hard since
PHP can easily jump in and out of the output like this:
<?php
if ($sometest){
?>

massive amount of plain HTML

<?php
} else {
?>

massive amount of plain HTML
<?php
}
?>
It saves you a lot of extra work to simple 'jump back to html'.
>
Anyway.. Am I barking up the wrong tree completely?
No, good tree. :-)
>
Thanks in advance

Doug.
Regards,
Erwin Moller
Apr 3 '07 #3
echo "<div id='success'>Thanks, here are the links you are looking
for....</div>";

Apr 3 '07 #4

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

Similar topics

4
by: Gregory | last post by:
Hello, I've managed to build two web pages, one that can display images with associated text data in a table, and one that can resize and display images without the text. I'd like to resize the...
2
by: Steven | last post by:
Hi there, I have a list of values that I am displaying in a table (Not using a loop) I want to be able to put a graphic next to the item with the hightest price. I have all of the prices in...
11
by: Ian Davies | last post by:
Hello Im having problems displaying my images as thumbnails in a table. My code for producing the new width and height from the original image is as follows...
15
by: Jameson | last post by:
Happy New Year, Everyone! I am trying to figure out how to display a bunch of images (mainly JPEGs, but possibly a few GIFs and PNGs as well) that are stored in a local directory on the system....
4
by: MrL8Knight | last post by:
Hello, I am trying to build a simple php form based shopping cart using a cookie with arrays. I need to use 1 cookie because each order will have over 20 items. With that said, I realize I need to...
13
by: Ray Muforosky | last post by:
Hello all: Task: I want to do file search, using the "conatining text" option from a web page. How do I search for a file on my local drive containing a certain string, from a web page. That...
11
by: kavithadevan | last post by:
Hi, Here i pasted Three scripts first one is displaying the details which i have stored in database this is working but in second script is in link with first one if i click main.php it...
3
by: mikec87 | last post by:
I am very new with PHP...started doing this a few days ago to help someone and I need some help please. I have a webpage that is not displaying the records I want it to. The sql is correct, and I...
11
by: dba | last post by:
Have been displaying data from database using html for some time but just recently trying to display data back to "form". Can't find answer. <form method="post" action="<?php echo $PHP_SELF;?>">...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.