I just started learning PHP and I tried looking for answers, but couldn't find any.

When i type in

<?php echo '<p>Order processed.

embedded into HTML, it works fine, but when I put

<?php echo '<p>Order processed.</p>' ?>

it always has the closing tag '?> shown in the browser. Is there something I missed?
When I run it through localhost/file_name in my browser, it works fine, but I would prefer just opening the php file from my desktop. Also, when I write:

<?php
	echo "<p>Order processed at ";
	echo date('H:i, jS F Y');
	echo "</p>";
      ?>

it seemingly ignores all the semicolons and treats echo and everything else as HTML.


What can I do to fix it?

Recommended Answers

All 4 Replies

Member Avatar for diafol

You need to open it in a browser via the localhost server. This is what processes the code. Just opening it up as a random file from anywhere will not work.

I put the files into the Apache htdocs directory, but when I click "Submit Order" on the .html file to access the processorder.php file, it does not work. Only when I run the .php file separately writing localhost/processorder.php does it work. Did I do something wrong when configuring PHP/Apache?

Member Avatar for diafol

It depends on the address of the html file in the address bar of the browser. If it's a local filepath like:

file:///C:/xampp/htdocs/index.html

Then using that to link to a php probably won't work.
If you open it as:

http://localhost/index.html

Then I can't see why the form won't work.

Show your form code.

It might be your apache configuration, sometimes PHP is not enabled. Within the httpd.conf file there is a sections called modules, find the line for loading the PHP module, and remove the '#' at the beginning. Save the file, and restart the web server. This should solve it.

However we need more detail, if you could try this.

  • Open your form in a web browser.
  • click view source
  • in the form attributes, where it would state the name of the php file, click it from the source still
  • Tell us what happens, does it work then or fail?
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.