Code2Design.com

User login

The Layout

Programming

Graphic Design

Resources

Navigation

C2D Projects

Unsystematic Affiliates

Photoshop Cafe Pixel Digest Christian Cosmos Proof That God Exists 

Change Language

Who's online

There are currently 0 users and 23 guests online.

Newbie stuck - php doesn't seem to want to work

Hi all,

Just found this site - hope you can help this newbi out.

I am just learning (or trying to) PHP. I have installed apache, php5, etc on my machine, and when i bring up a browser (firefox or ie) nothing seems to work.

Here is the simple code i copied from a tutorial...

<?php
$site_name 
"This is the site name area";
$paragraph_text "Welcome to my site";
$email 'type me@email.com';
?>


<html>
<body>
<h2><?php echo $site_name?></h2>
<p><?php echo $paragraph_text?></p>
<p>Email me: <a href="mailto:<?php echo $email?>"><?php echo $email?></a>
</body>
</html>

====================================================

When i try to run it, the only thing displayed is "Email me:" - without the quotes.

===========================================

When i display the page source (and correct me if i'm wrong, but the php code should not show up - it displays the following....

<?php
$site_name 
"This is the site name area";
$paragraph_text "Welcome to my site";
$email 'type me@email.com';
?>


<html>
<body>
<h2><?php echo $site_name?></h2>
<p><?php echo $paragraph_text?></p>
<p>Email me: <a href="mailto:<?php echo $email?>"><?php echo $email?></a>
</body>
</html>

========================================

I'm sure there's a very simple explanation for this, but it's my first ever try at doing anything on the web (been an application / system programmer for 35 years) and I'm at a loss.

Thanks in advance,
Q


Submitted by quadlo on May 6, 2008 - 3:36pm.
printer friendly version

Why PHP doesn't work

Well, if the PHP code is not being processed you must be a victim of one of the following:

A) Not have the right file extension (make sure it is "name.php" and not "name.php.txt" or "name.html"

B) Not have the PHP file in the root of the server (so PHP can process it)

C) Not have PHP set to process .php files.

Also, I recomend installing WAMP as it is a GREAT OS system for running multiple versions of PHP4-5, MySQL 4-5, and Apache 1-2 with no added headaches. A lot easyer than installing them on your own - plus it is pre-configured.


Why PHP doesn't work

Thanks for the reply.

My files are names something.php, but i did check to make sure.

I used the wamp distribution as you suggested, and have put the files in D:\xampp\htdocs\LearningPHP --- is this ok?

About setting php to process php files - haven't a clue how to do this - or if it's already been set - any info on this would surely be appreciated.

I have also installed joomla - which works beautifully - it does use lots of php code, so i think my settings re: php are maybe correct?

Here's a dumb question for you - if you embed php code in html, shouldn't the file extension be something.html for the html code to work? Again, any insight would be appreciated.

Thanks in advance,

Jay


PHP in HTML

PHP will only be processed in files that the server (apache or IIS) gives it to process. The default is that only .php or .php3 files are given to the PHP core for processing. However, you can change it so that .html or even .txt are also given to the PHP core to be processed (but there is no reason to).

HTML code in .asp, .php, .html, etc will always be processed by the browser. You don't need a file to be .HTML for html code to work.

I don't have more than 2-3 html files in all 10+ of my sites.

Also, xampp is just like wamp so you are fine. I just thought you did your own install of L.A.M.P. Still, you need to go to tools->folder options->view and uncheck "hide extensions for known file types". I bet you are saving php files as name.php.txt but all you see is "name.php"


Why PHP doesn't work

Again, thanks for the answer.

The file I am trying to get to work is a ".php" file.

Extensions for know file types are not hidden.

I understand now about mixing html and php - just put all of the stuff in a ".php" file, and, in theory, all should work just file. ---- except in my dumb machine.

I'm at a complete loss here - I know I must be doing something so very simple wrong that I can't see it - but for the life of me, haven;t a clue.

Jay


Why PHP doesn't work

If you could see how red my face is.

I have been dragging and dropping the php file into my browser.

I changed (ok, so I'm really lazy) and typed in localhost....... and imagine what happened - yup - works

Boy am I ever ashamed

Quadlo


It's the simple things

lol, I know what you mean.

I spent all day on a problem only to find that I miss-spelled a variable name and so the whole script kept crashing!


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br> <br /> <h3>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use BBCode tags in the text, URLs will be automatically converted to links
More information about formatting options



Like what you see?

Why not add more? C2D is looking for other Christian Web Masters who would like to help write articles for this site. If you have expericance in FLASH, CSS/HTML, PHP/MySQL, PhotoShop/GIMP, Blender, Javascript, or just General Design - our users would love to hear what you have to say. Contact Us

delicious   digg   reddit   magnoliacom   newsvine   furl   google   yahoo   technorati