This is my html. When I put name and press ENTER , browser opening download box for report.php . I don't know how to fix that. I have Apache MySQL started. Windows 8.

<form action="report.php" method="post">

<label for="Your Name">Your Name</label>

<input type="text" id="firstname" name="firstname"><br>
</form>

this is report.php

<?php 
$first_name = $_POST['firstname'];

echo 'Your name is'. $first_name;
?>
Member Avatar
diafol

It's usually because Apache not running or your php pages are outside the server localhost / virtual host directory. Are you running XAMPP?

Have you set it up properly in your hosts and vhosts files? Usual locations...

C:\xampp\apache\conf\extra\httpd-vhosts.conf
C:\Windows\System32\drivers\etc\hosts

Example:

vhosts

<VirtualHost *:80>
 DocumentRoot "C:/xampp/htdocs/books"
 ServerName books
 <Directory "C:/xampp/htdocs/books">
  Order allow,deny
  Allow from all
 </Directory>
</VirtualHost>

hosts

127.0.0.1       localhost
::1             localhost

127.0.0.1       books

Thanks Diafol, I amusing xampp. I find my vhost and host file. Now where to put or replace the code blocks you given?

Member Avatar
diafol

place these at the end of the files. You don't need to put

127.0.0.1       localhost
::1             localhost

in the hosts file again - should be there already.
So my examle would give the localhost virtual server...

http://books/ 

Remember to stop and restart Apache every time you make changes to these files

I actually did. I placed the two lines at the bottom of the two files. But still has same problem :( . Can't work on local

Member Avatar
diafol

I'm confused now. The lines

127.0.0.1       localhost
::1             localhost

SHould be inside hosts file already - so no need to add them again.

You only need to add

127.0.0.1       books

to hosts

ANd

<VirtualHost *:80>
 DocumentRoot "C:/xampp/htdocs/books"
 ServerName books
 <Directory "C:/xampp/htdocs/books">
  Order allow,deny
  Allow from all
 </Directory>
</VirtualHost>

to httpd-vhosts.conf

Sorry if that's what you did - it was unclear from this...

I placed the two lines at the bottom of the two files.

Do you get the xampp start page when you go to http://localhost?

The index.php page in the xampp/htdocs directory should have this:

<?php
    if (!empty($_SERVER['HTTPS']) && ('on' == $_SERVER['HTTPS'])) {
        $uri = 'https://';
    } else {
        $uri = 'http://';
    }
    $uri .= $_SERVER['HTTP_HOST'];
    header('Location: '.$uri.'/xampp/');
    exit;
?>
Something is wrong with the XAMPP installation :-(

It simply redirects to the xampp/htdocs/xampp/index.php page. You may find that the header() line has been commented out [or did I do that??? I can't remember :)]

http://localhost should give you the xampp start page. If not there may be something wrong with your setup.

I can't save host file. It is probably opened on another program. How to fix that? Thanks that you are trying to help.

Member Avatar
diafol

I can't see which other program would prevent you from doing that. I suggest rebooting your computer and trying again.

WOW...Diafol ..It works. Actually, I was so much worried. But after rebooting computer it works. Thanks for your great help and patience.