Hi,
I am trying to get this form to submit the entered details into a mysql database, I have it working as such but the entries are just 1 in each fiels of the database with the exception of the date. Would you mind haveing a look at my code to see if you can see why this is happening please, I would be very greatful.
Thanks,
Phil
if (isset($_POST['submit'])) { // Handle the form.
require_once ('./mysql_connect.php'); // Connect to the db.
// Check for a name.
if (strlen($_POST['first_name']) > 0) {
$first_name = TRUE;
} else {
$first_name = FALSE;
$message .= '<p>You forgot to enter your first name!</p>';
}
// Check for a last name .
if (strlen($_POST['last_name']) > 0) {
$last_name = TRUE;
} else {
$last_name = FALSE;
$message .= '<p>You forgot to enter your last name!</p>';
}
// Check for an email address.
if (strlen($_POST['email']) > 0) {
$email = TRUE;
} else {
$email = FALSE;
$message .= '<p>You forgot to enter your email address!</p>';
}
// Check for a country.
if (strlen($_POST['country']) > 0) {
$country = TRUE;
} else {
$country = FALSE;
$message .= '<p>You forgot to enter your country!</p>';
}
}
if ($first_name && $last_name && $email && $country) { // If everything's okay.
// Register the user.
// Make the query.
$query = "INSERT INTO employees (first_name, last_name, email, country, registration_date) VALUES ('$first_name', '$last_name', '$email', '$country', NOW() )";
$result = @mysql_query ($query); // Run the query.
if ($result) { // If it ran OK.
// Send an email.
// To send HTML mail, the Content-type header must be set
$to = $_POST['email'];
$subject = 'Form Registration'; // Create an empty new variable.
$message = "Thank you for registering with our site!\n\nYour login first name is '{$_POST['first_name']}' and your email is '{$_POST['email']}'\n\nPlease visit http://www.phwebdesign.co.uk/login.php to login\n\nSincerely,\n\nPHWEBDESIGN.CO.UK";
$headers .= 'From: admin@phwebdesign.co.uk' . "\r\n";
$headers .= 'Bcc: forms@phcleaning.co.uk' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
header ('Location: thankyou.php');
exit();
} else { // If it did not run OK.
$message = '<p>You could not be registered due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>';
}
mysql_close(); // Close the database connection.
}
// End of the main Submit conditional.
// Set the page title and include the HTML header.
$page_title = 'Register!';
// Print the error message if there is one.
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
Here is the form that goes with it.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>First Name:</b> <input name="first_name" type="text" id="first_name" value="<?php if (isset($POST['first_name'])) echo $POST['first_name']; ?>" size="20" maxlength="40" />
</p>
<p><b>Last Name:</b> <input type="last_name" name="last_name" size="20" maxlength="40" value="<?php if (isset($POST['last_name'])) echo $POST['last_name']; ?>" />
</p>
<p><b>Email:</b> <input name="email" type="text" id="email" value="<?php if (isset($POST['email'])) echo $POST['email']; ?>" size="40" maxlength="60" />
</p>
<p><b>Country:</b> <input type="text" name="country" size="20" maxlength="40" /></p>
</fieldset>
<div align="center"><input type="submit" name="submit" value="Submit Information" /></div>
</form><!-- End of Form -->