954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

My First PHP Script


My first program and its a failure

hsetaknev
Newbie Poster
24 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

What is your "desired output"? Because this output looks fine to me

n_e
Junior Poster in Training
97 posts since Feb 2010
Reputation Points: 10
Solved Threads: 8
 

Try this:

<html>
<head>
<title>My first PHP By my own</title>
</head>
<body>
<?php
echo "My first program and its a failure";
?>
</body>
</html>

You should not have the plain text directly between the head tags. You can do in body tags. Also, you must write semi-colon ';' at the end of every PHP statements.

Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
 

Zero13 is correct. Also don't forget to save the file with a ,php extention, also save it in htdocs folder if your are using APACHE.

faroukmuhammad
Junior Poster
140 posts since Sep 2008
Reputation Points: 20
Solved Threads: 16
 
you must write semi-colon ';' at the end of every PHP statements

You do not need to have a semicolon terminating the last line of a PHP block.
The closing tag for the block will include the immediately trailing newline if one is present.

You can refer to the manual of PHP:
http://www.php.net/manual/en/language.basic-syntax.instruction-separation.php

Pro2000
Posting Whiz
351 posts since Jun 2007
Reputation Points: 44
Solved Threads: 23
 

http://www.w3schools.com/php/default.asp refer this site its very useful for the beginners.

Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 
What is your "desired output"? Because this output looks fine to me


wont i get an out put like a homepage of website

hsetaknev
Newbie Poster
24 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 
Zero13 is correct. Also don't forget to save the file with a ,php extention, also save it in htdocs folder if your are using APACHE.


what is ZERO13

hsetaknev
Newbie Poster
24 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 
http://www.w3schools.com/php/default.asp refer this site its very useful for the beginners.


@karthik I am using w3school.com to learn already even this code i learnt frm der

hsetaknev
Newbie Poster
24 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 


My first program and its a failure

hsetaknev
Newbie Poster
24 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 
what is ZERO13


sorry @zero13 i only later noted u r screen name

hsetaknev
Newbie Poster
24 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

Are you sure you've already downloaded PHP and it is properly setup on your machine ? What server are you using ? Microsoft IIS or any third-party ? I suggest to use WAMPP or XAMPP if you're windows user, you can also use MAMPP on Mac. So, check the above question. You must install and configure PHP engine on your machine first. You can download PHP manually here . Download XAMPP here .

Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
 
Are you sure you've already downloaded PHP and it is properly setup on your machine ? What server are you using ? Microsoft IIS or any third-party ? I suggest to use WAMPP or XAMPP if you're windows user, you can also use MAMPP on Mac. So, check the above question. You must install and configure PHP engine on your machine first. You can download PHP manually here . Download XAMPP here .

]@Zero13 am using Ubuntu 10.10
I used sudo apt-get install php-**
in my terminal so i am very sure that ive installed it

hsetaknev
Newbie Poster
24 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

You also need any web server such Apache, etc. Go here .

Zero13
Practically a Master Poster
624 posts since Jan 2009
Reputation Points: 120
Solved Threads: 139
 

Exactly, you need to install apache2, php for apache and mysql for apache. Use the packet installer (don't remember what is called in ubuntu)

Anyway, you've installed php correctly. The output you get from the terminal is correct.

php parses the code, then outputs HTML code. So the result you're getting is correct and will be interpreted by a web browser as a webpage. The problem is that you're parsing the code at the terminal, so that's the output you get, the html code.

Install apache and its php module and then put your file inside the HTML directory of apache. Then just access your file through your browser

http://localhost/asp.php

mikeflash
Newbie Poster
12 posts since Aug 2010
Reputation Points: 10
Solved Threads: 1
 

@zERO13 ARE THERE ANY DESIGN MODE EDITOR OR KINDA FRONTEND TOOL like FRONTPAGE
IN WINDOWS FOR UBUNTU

hsetaknev
Newbie Poster
24 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

It seems to me that you are trying to run the script from the command line instead of displaying it in a browser.

In general with PHP you can make two types of scripts:
- applications which are run from command line (php scriptname.php)
- and scripts which are processed on the web server and the result displayed in a browser

You seem to want to do the later since you have PHP within Html code. In this case you have to set up a web server (Apache, Lamp,...) or get web hosting, put the script in appropriate directory and open it with a web browser pointing to specific address.

Judging from your post you have Linux so install and start Apache, put the script in /var/www/html (or similar) and open it with the browser at http://localhost . There are many tutorials arround on how to install, configure and startApache.

broj1
Posting Whiz
359 posts since Jan 2011
Reputation Points: 29
Solved Threads: 43
 

As far as editors are concerned for serious use most people recommend PHP Eclipse http://www.phpeclipse.com/ , but it might be to overwhelming for a beginner. If you have Gnome then gedit is very good to start with, if you use KDE then KWrite is equivalent. Try one of these and plan to start learning Eclipse as you get more proficient in PHP.

broj1
Posting Whiz
359 posts since Jan 2011
Reputation Points: 29
Solved Threads: 43
 

I think AppServ has the integrated needed package (PHP, MySQL) and Recently ZEND and a PHP text processor.

Pro2000
Posting Whiz
351 posts since Jun 2007
Reputation Points: 44
Solved Threads: 23
 

Friend, copy\paste this into new .php file , save it as something.php and it will work:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Expires" content="Fri, Jan 01 1900 00:00:00 GMT">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Lang" content="en">
<meta name="author" content="">
<meta http-equiv="Reply-to" content="@.com">
<meta name="generator" content="PhpED 5.8">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="creation-date" content="01/01/2009">
<meta name="revisit-after" content="15 days">
<title>MySite</title>
<link rel="stylesheet" type="text/css" href="my.css">
</head>
<body>
  <?php
      echo("This is my crazy script!");
    ?>
</body>
</html>
tnjiric
Newbie Poster
21 posts since Jul 2011
Reputation Points: 15
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
 
View similar articles that have also been tagged: