I’m currently working on an assignment for my PHP class. My goal is for the user to enter data and that data gets added to a SQL database after it is validated. My problem is when I press submit, I get an error 403. This is using a WAMP server setup. Below is my code.
[php]
<?php
//Initialize pagetitle, include header file and connect file for connecting to DB
$pagetitle = 'John Brintnell, IT250, Unit 4';
include('includes/header.php');
?>
Please sign my guest book!
First
Last
Email Address
Password
Confirm Password
Comment
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
// Validate the input values
if(isset($_POST['fname'])) // NULL value permitted
$fname=trim($_POST['fname']);
if(isset($_POST['lname'])) // NULL value permitted
$lname=trim($_POST['lname']);
if ($_POST['password1']!= $_POST['password2']){
echo("Oops! Password did not match! Try again. ");
exit;
}
else {
$password=trim($_POST['password1']);
}
if(isset($_POST['email']) && !empty($_POST['email'])) { // No NULL value
$email=trim($_POST['email']);
if(preg_match("/^[a-z0-9._-]+@[a-z0-9_-]+(\.[a-z0-9_-]
+)*(\.[a-z]{2,3})$/i", $email) == 0) { // Email validation
echo "The email address is invalid.";
exit;
}
}
else {
echo "You must enter your email address.";
exit;
}
if(isset($_POST['comment'])) // NULL value permitted
$comment=trim($_POST['comment']);
}
else {
exit;
}
//establish database connection
require 'connect.php';
// insert record into database table guests
$sql="INSERT INTO guests(fname, lname, email, password, comment)
VALUES ('$fname', '$lname', '$email', '$password', '$comment')";
$result = @mysqli_query($connect, $sql) or die(mysqli_error());
if($result) {
echo "
One record has been added to contact table!
";
}
// Close the database connection
mysqli_close($connect);
include ('includes/footer.php');
?>
[/php]
Other programs I’ve created in previous units still work correctly.