So, I decided to completely rewrite the form and script stuff to make it better, and I'm part of the way there. I have the error checking stuff working, but when I hit the submit button, nothing happens! It doesn't send me to the thanks.php form, and nothing ends up in my db. Here is the new code I'm using. Any suggestions would be greatly appreciated!
dbconnect.php
<?php
// load the database library
include('/usr/share/pear/DB.php');
$dbtype = "mysql";
$dbuser = "username";
$dbpassword = "password";
$dbhost = "some.server.com";
$dbname = "dbname";
$connection = $dbtype.'://'.$dbuser.':'.$dbpassword.'@'.$dbhost.'/'.$dbname;
$database = DB::connect($connection);
?>
This is the form
<?php
// connect to the database
include('dbconnect.php');
$error = false;
// run this only, once the user has hit the "Submit" button
if (isset($_POST['submit'])) {
// assign form inputs
$name = $_POST['name'];
$email = $_POST['email'];
$site = $_POST['site'];
$url = $_POST['url'];
$subcategory = $_POST['subcategory'];
$description = $_POST['description'];
$location = $_POST['location'];
$status = $_POST['status'];
// validate inputs
if ( !empty($firstname) && !empty($lastname) && !empty($url)) {
// add member to database
$query = "INSERT INTO Testinput (SubmitterName,SubmitterEmail,SiteName,URL,SubCategory,Description,Location,Status) VALUES ('".$name."','".$email."','".$site."','".$url."','".$subcategory."','".$description."','".$location."','".$status."')";
$result = $database->query($query);
$database->disconnect();
$message = "Your site has been successfully added.";
Header("Location: thanks.php");
exit;
}
else {
$error = true; // input validation failed
}
}
?>
<html>
<head>
<title>Add a Site</title>
</head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php
if ( !empty($message) ) {
echo '<span style="color:green">',$message,'</span><br><br>',"\n";
}
?>
<?php
if ( $error && empty($name) ) {
echo '<span style="color:red">Error! Please enter your name.</span><br>',"\n";
}
?>
<p>Your Name:
<input name="name" type="text" value="<?php echo $name; ?>">
<br>
<?php
if ( $error && empty($email) ) {
echo '<span style="color:red">Error! Please enter your email address.</span><br>',"\n";
}
?>
Your Email:
<input name="email" type="text" value="<?php echo $email; ?>">
<br>
<?php
if ( $error && empty($url) ) {
echo '<span style="color:red">Error! Please enter site address.</span><br>',"\n";
}
?>
<p>Site Name:
<input name="site" type="text" value="<?php echo $site; ?>">
<p>Site Address:
<input name="url" type="text" value="<?php echo $url; ?>">
<p>SubCategory:
<input name="subcategory" type="text" value="<?php echo $subcategory; ?>">
<br>
<br>
Site Description:<br>
<textarea name="description" cols="40" rows="4"><?php echo $description; ?></textarea>
<br>
<p>Location:
<input name="location" type="text" value="<?php echo $location; ?>">
<p>Status:
<input name="status" type="text" value="<?php echo $status; ?>">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>