Browser ask me to download php file

  • amrelewa
  • Born
  • Born
  • amrelewa
  • Posts: 2

Post 3+ Months Ago

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 Code: [ Select ]
<?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();
?>
  1. <?php
  2.  
  3. define('DB_NAME', 'newdb');
  4. define('DB_USER', 'root');
  5. define('DB_PASSWORD', 'root');
  6. define('DB_HOST', 'localhost');
  7.  
  8. $link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
  9.  
  10. if (!$link) {
  11.     die('Could not connect: ' . mysql_error());
  12. }
  13.  
  14. $db_selected = mysql_select_db(DB_NAME, $link);
  15.  
  16. if (!$db_selected) {
  17.     die('Can\'t use ' . DB_NAME . ': ' . mysql_error ());
  18. }
  19.  
  20. $value = $_POST['firstname'];
  21.  
  22. $sql = "INSERT INTO users (firstname) VALUES ('$value')";
  23.  
  24. if (!mysql_query($sql)) {
  25.     die('Error: ' . mysql_error());
  26. }
  27.  
  28. mysql_close();
  29. ?>


HTML Code: [ Select ]
<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>
  1. <html>
  2. <head>
  3. <title></title>
  4. <meta name="description" content="" />
  5. <meta name="keywords" content="" / >
  6. <link rel="stylesheet" type="text/css" href="mystyle.css" />
  7. </head>
  8.  
  9.  
  10. <body>
  11. <div id="container">
  12.     <div id="header">
  13.         <a href="index"><div id="logo">
  14.         </div></a>
  15.     </div>
  16. <div calss="hr"><hr /></div>
  17. <div id="incontainer">
  18.  
  19. <!-- Beginning of Content -->
  20.  
  21. <h2>Sign Up</h2>
  22. <form action="users.php" method="post" />
  23.     <p>First Name:<input class="rounded" type="text" name="firstname" /></p>
  24.     <input type="submit" value="Submit" />
  25. </form>
  26.  
  27. <!-- End of Content -->
  28.  
  29. </div>
  30. <footer>
  31.     <div calss="hr"><hr />
  32.     <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>
  33.     <h3>Copyright © 1990-2011</h3>
  34. </footer>
  35.  
  36.  
  37. </div>
  38. </body>
  39. </html>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9086
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

When it prompts you to download the file, have you ever downloaded it? If you haven't download it and open it to see if its your actual PHP file, or instead some sort of error message.
  • amrelewa
  • Born
  • Born
  • amrelewa
  • Posts: 2

Post 3+ Months Ago

Thank you. I fixed the problem, by putting the files on the right place "htdocs" and browse by using localhost/filename rather double click on the file.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 117 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.