Browser ask me to download php file

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 12940 Views - Last Post: 21 January 2012 - 08:30 PM

#1 amrelewa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-March 11

Browser ask me to download php file

Posted 29 March 2011 - 12:51 PM

Hello everyone,

I am a new guy in web programming who still learning new stuff. I am creating a web form that consist of one INPUT. I connected the form in the HTML file to the php file. I am using a localhost MAMP that I recently installed on my MacBook. When I open the HTML file on a webpage and type something on the input box and hit submit, the browser ask me to download the php file rather processing it. I don’t think the problem is related to mysql or apache since when I run the MAMP it give me green signs next to the apache and mysql. The following is the whole script for the HTML file as well as the PHP file. Do anyone know how I can fix this problem and let the php file open and transfer inputs to the database?

<?php

define('DB_NAME', 'newdb');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');
define('DB_HOST', 'localhost');

$link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);

if (!$link) {
    die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$db_selected) {
    die('Can\'t use ' . DB_NAME . ': ' . mysql_error ());
}

$value = $_POST['firstname'];

$sql = "INSERT INTO users (firstname) VALUES ('$value')";

if (!mysql_query($sql)) {
    die('Error: ' . mysql_error());
}

mysql_close();
?>

-----------------------------------------------------------------------------------

<html>
<head>
<title></title>
<meta name="description" content="" />
<meta name="keywords" content="" / >
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>


<body>
<div id="container">
    <div id="header">
        <a href="index"><div id="logo">
        </div></a>
    </div>
<div calss="hr"><hr /></div>
<div id="incontainer">

<!-- Beginning of Content -->

<h2>Sign Up</h2>
<form action="users.php" method="post" />
    <p>First Name:<input class="rounded" type="text" name="firstname" /></p>
    <input type="submit" value="Submit" />
</form>

<!-- End of Content -->

</div>
<footer>
    <div calss="hr"><hr />
    <a href="about">About  </a>-<a href="contact"> Contact </a>-<a href="#"> Privacy </a>-<a href="#"> Legal </a>-<a href="#"> Help </a>-<a href="#"> Career </a>
    <h3>Copyright © 1990-2011</h3>
</footer>


</div>
</body>
</html>


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 29 March 2011 - 01:16 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Browser ask me to download php file

#2 xZachtmx   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 125
  • Joined: 14-June 09

Re: Browser ask me to download php file

Posted 29 March 2011 - 01:49 PM

This happens when you don't have PHP installed properly on your web server. Nothing wrong with your code.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4217
  • View blog
  • Posts: 13,328
  • Joined: 08-June 10

Re: Browser ask me to download php file

Posted 29 March 2011 - 01:53 PM

often this is the case when PHP is not registered properly at the Apache server. Apache needs to be told that php files have to be passed to the PHP interpreter. check your httpd.conf file.

PS. check out MacPorts, I find it easier to customize.

This post has been edited by Dormilich: 29 March 2011 - 01:57 PM

Was This Post Helpful? 0
  • +
  • -

#4 amrelewa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-March 11

Re: Browser ask me to download php file

Posted 29 March 2011 - 02:00 PM

I enabled PHP5 on my mac according to this website's instructions http://foundationphp...php_leopard.php

Also, I read that php is already installed on OS X 10.5 or later, and I am using OS X 10.6.7

I think my apache is working fine, since I am recently installed in and didn't made any changes in the files. Also, it give me green sign when I run the localhost.
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4217
  • View blog
  • Posts: 13,328
  • Joined: 08-June 10

Re: Browser ask me to download php file

Posted 29 March 2011 - 02:05 PM

Mac 10.5+ indeed come with Apache2 & PHP preinstalled. although the default PHP lacks some useful functionality and is not customisable.

when using more than one server (i.e. default & MAMP) be sure to either configure them to listen to different ports* (httpd.conf) or disable all but one.


* - that’s what I did, one is listening to port 8080 and runs PHP 5.2, the other one listens to port 80 and runs PHP 5.3

This post has been edited by Dormilich: 29 March 2011 - 02:07 PM

Was This Post Helpful? 1
  • +
  • -

#6 amrelewa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-March 11

Re: Browser ask me to download php file

Posted 29 March 2011 - 02:20 PM

I agree with you, and i did what exactly you mentioned. But still the browser ask me to download the PHP file when I hit submit.
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4217
  • View blog
  • Posts: 13,328
  • Joined: 08-June 10

Re: Browser ask me to download php file

Posted 29 March 2011 - 02:32 PM

you know what to add in the httpd.conf file? maybe you need to find the config file of the running server Ö
Was This Post Helpful? 0
  • +
  • -

#8 amrelewa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-March 11

Re: Browser ask me to download php file

Posted 29 March 2011 - 02:38 PM

I changed the document root to a folder in the desktop named website. In this folder I added all the website files. I feel the problem is not related to the APACHE or MYSQL in my computer, and its about the php file extension or something like that, which I am not aware of. I made sure that the extension of the file is php and no hidden extensions. but I still feel that there is something missing.
Was This Post Helpful? 0
  • +
  • -

#9 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4217
  • View blog
  • Posts: 13,328
  • Joined: 08-June 10

Re: Browser ask me to download php file

Posted 29 March 2011 - 02:40 PM

have you checked your httpd.conf files?
Was This Post Helpful? 0
  • +
  • -

#10 amrelewa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-March 11

Re: Browser ask me to download php file

Posted 29 March 2011 - 03:10 PM

I did not. What I didnt understand what I should do with httpd.conf file
Was This Post Helpful? 0
  • +
  • -

#11 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4217
  • View blog
  • Posts: 13,328
  • Joined: 08-June 10

Re: Browser ask me to download php file

Posted 29 March 2011 - 10:29 PM

Iím telling you since post #3 that in this file is defined, what Apache is supposed to do with PHP files.
Was This Post Helpful? 0
  • +
  • -

#12 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6698
  • View blog
  • Posts: 31,070
  • Joined: 10-May 07

Re: Browser ask me to download php file

Posted 29 March 2011 - 10:46 PM

** Moved to Web Servers & Hosting **

View Postamrelewa, on 29 March 2011 - 05:38 PM, said:

I feel the problem is not related to the APACHE or MYSQL in my computer

You are asking Apache to display a php file. The httpd.conf will dictate Apache's behavior with specific file extensions (like htm, html, & php). If the php file extension is not defined, then Apache will not know to hand the file to the php engine (assuming one is installed). Thus it offers it for a download instead.

Feel free to check your Apache logs.
Was This Post Helpful? 0
  • +
  • -

#13 amrelewa   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-March 11

Re: Browser ask me to download php file

Posted 29 March 2011 - 11:01 PM

I was wrong .. I didnt put the files on the right place. I am finally fixed the problem. You are all awesome guys and thaaaanks for help.
Was This Post Helpful? 0
  • +
  • -

#14 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6698
  • View blog
  • Posts: 31,070
  • Joined: 10-May 07

Re: Browser ask me to download php file

Posted 29 March 2011 - 11:02 PM

Glad to see that you got it fixed!
Was This Post Helpful? 0
  • +
  • -

#15 ymtaher   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 21-January 12

Re: Browser ask me to download php file

Posted 21 January 2012 - 07:39 PM

View Postno2pencil, on 29 March 2011 - 11:02 PM, said:

Glad to see that you got it fixed!


Hello all, I am new to this interesting forum.

I have a question related to this thread.

PHP files are normally opened on my local Apache server, but there is one certain website that makes Firefox asks me to download/open php files from that website. This website is developed by one of my friends, and I am trying to help him, but I can't make that website running on my local machine.

I'd be grateful if you have any helpful recommendations.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2