Hi people! I'm new to this forum, so a very warm welcome from me :).
I have just started PHP because I want to construct a website and i'm trying to figure out what is going wrong?
HelloWorld.PHP - basic program trying to make it work. I'm using Adobe CS5 Dreamweaver.
Source code:
<html>
<body>
<?php
echo 'Hello';
?>
</body>
</html>
This prints nothing. I checked on Google Chrome, Firefox and IE. It doesn't print anything. Why?
I used DreamWeaver PHP template:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
echo 'Hello';
?>
</body>
</html>
Still printed nothing. Then I made this change:
<html>
<body>
<?php
echo '<p>Hello</p>';
?>
</body>
</html>
This outputted:
Hello
'; ?>
Why does it output " '; ?> " when that is not in the parameters? I can't seem to get rid of it
Do I need XAMPP? Is that the problem? Because all I am doing is making it on dreamweaver with .php extension and dragging it onto Chrome and/or Firefox to see the result.
Thank you for all your generous and helpful replies :),
Zukky.
Beginner - Trying to understand why echo is not printing correctly?
Started by Zukky, Sep 06 2011 06:17 PM
3 replies to this topic
#1
Posted 06 September 2011 - 06:17 PM
|
|
|
#2
Posted 06 September 2011 - 07:43 PM
There are two possibilities I can determine right away,
If you browse the source of the empty page on Firefox, it may actually show you the PHP code hidden in pink as the browser is not really supposed to be viewing PHP, only its result.
If this is the case, feel free to look at the FAQ of this forum section, there are links to XAMPP to (easily) get a basic server capable of PHP parsing on your computer, so you can view http://localhost/page.php to test just as you would on a web server.
If I have mistaken, just tell me.
Alexander.
- Does the file you are running in the web browser have a .php extension?
- Are you viewing the php file directly (i.e. c:\...\file.php) ?
If you browse the source of the empty page on Firefox, it may actually show you the PHP code hidden in pink as the browser is not really supposed to be viewing PHP, only its result.
If this is the case, feel free to look at the FAQ of this forum section, there are links to XAMPP to (easily) get a basic server capable of PHP parsing on your computer, so you can view http://localhost/page.php to test just as you would on a web server.
If I have mistaken, just tell me.
Alexander.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 07 September 2011 - 02:12 PM
Hi Alexander,
Thank you very much for your advice. I didn't really understand that it was server-sided, now I do :). Thanks for that ;).
It does have a .PHP extension, yes I am viewing directly.
I installed XAMPP and everything seems to be working fantastic :)! So when I upload this to my website FTP, it should parse and work correctly? (Stupid question i'll test and report back). I have a domain name registered with GoDaddy.com and their hosting servers too. If you have any experience with them, do you have any good tips with FTP and PHP use?
I want to add a Google Maps API to my site. Would it be smart to have HTML with a query box that is displayed on the PHP page on a Google Maps API?
Thank you,
Zukky.
Thank you very much for your advice. I didn't really understand that it was server-sided, now I do :). Thanks for that ;).
It does have a .PHP extension, yes I am viewing directly.
I installed XAMPP and everything seems to be working fantastic :)! So when I upload this to my website FTP, it should parse and work correctly? (Stupid question i'll test and report back). I have a domain name registered with GoDaddy.com and their hosting servers too. If you have any experience with them, do you have any good tips with FTP and PHP use?
I want to add a Google Maps API to my site. Would it be smart to have HTML with a query box that is displayed on the PHP page on a Google Maps API?
Thank you,
Zukky.
#4
Posted 07 September 2011 - 05:17 PM
Quote
So when I upload this to my website FTP, it should parse and work correctly?
The major difference will be settings however, web hosts often restrict settings and may apply PHP's safe mode which will disallow things such as fopen to be used on web addresses. Although most of safe mode's restrictions only affect specialty applications, you may not easily be able to retrieve data from an URL with PHP, which may or may not be a problem for API access.
Quote
If you have any experience with them, do you have any good tips with FTP and PHP use?
PHP wise you should always develop offline on XAMPP, trying to match settings if applicable to your web host's. Be sure to test every aspect of your application, this can help avoid putting untested code online, and have somebody use some automated script testing various exploits or malformed input (i.e. user names) to try to exploit the database.
An at least brief understanding of what you can do to secure PHP applications will be golden, such as the rule "never trust user input", always make sure that it is properly handled and cleaned, so that they cannot type anything they shouldn't.
Quote
I want to add a Google Maps API to my site. Would it be smart to have HTML with a query box that is displayed on the PHP page on a Google Maps API?
You can embed PHP within HTML (as long as it is a .php extension). For example, assume the HTML form is designed to POST (method="post") to the same page, you can use a PHP script to handle its contents (or lack of contents, such as when they first view the page)
A rough example:
<form action="thispage.php" method="post">
<input type="input" name="form_location"/>
<input type="submit"/>
</form>
<?php
if( isset($_POST['form_location']) ) {
//query the map API for the data in $_POST['form_location']
} else {
echo "No location has been entered";
}
?>
There are many ways of doing this however, and Google may allow AJAX instead of PHP.
You may wish to follow various tutorials to get used to PHP's form handling, and general interaction with user input first before moving on.
We've also various PHP tutorials in our tutorials section (there is a sticky which links to the area) and a FAQ sticky in this section as well, feel free to ask any more questions as always :)
Alexander.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









