Forum Moderators: coopster
Code
*********************************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<?php
echo "<head><title>NHM</title></head>";
//Connect to database
$dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("mydbase"); $dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("mydbase");
//This code runs if the form has been submitted
if (isset($_POST['submit'])) {
//This makes sure they did not leave any fields blank
if (!$_POST['fname'] ¦!$_POST['email'] )
{
die('<table>
<tr>
<td>You must complete all fields</td>
</tr>
</table>');
}
// now we insert it into the database
$query = "INSERT INTO MY_Table (id, fname, email)
VALUES ('$id','$fname','$email')";
mysql_query($query);
mysql_close();
// mail user their information
$yoursite = "mysite.com";
$youremail = "admin@email.com";
$subject = "You have successfully enterd data";
$message = "A lead has been entered into the database.";
mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());
?>
<!-- Now we let them know if their entry was successful -->
<table>
<tr>
<td><h1>Successful Lead Entry</h1></td>
</tr>
</table>
<?php
}
else
{
?>
<body>
<table>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<tr>
<td >First Name: </td>
<td >
<input name="fname" type="text" id="fname" size="20"></td>
</tr>
<tr>
<td>Email:</td>
<td><input name="email" type="text" id="email" size="20"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="submit" value="Register" ></td>
</tr>
</form>
</table>
</body>
<?php
}
?>
</html>