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!!!
This post has been edited by JackOfAllTrades: 29 March 2011 - 01:16 PM

New Topic/Question
Reply


MultiQuote





|