I must be overlooking something incredibly obvious, but I've went through all my PHP code and compared it to the other forms that are working. I can't find any differences. Basically when I submit this form, it's not adding anything to the comments table in my database. There must be something incredibly obvious that I'm overlooking. Can you please help me figure out what I'm missing? Here's my php form first:
<?php
session_start();
require_once('functions/functions.php');
echo do_html(array('title'=>'Comments', 'css_file'=>'assets/css/style.css'));
echo do_header();
?>
<div id="usernameDiv"><?php echo do_greetings(); ?></div>
<div>
<p class="lead">We are always looking for new feedback, whether you have registered or not! Please leave your name and email address. Thank you!</p>
</div>
<form action="actions/comments.php" method="post">
First Name:<br>
<input type="text" name="fname">
<br>
Last Name:<br>
<input type="text" name="lname">
<br>
Email Address:<br>
<input type="text" name="eaddress"> <br><br>
<textarea name="ucomment" cols="50" rows="7" placeholder="Enter comments here..."></textarea>
<br><br>
<input type="submit" name="submitButton" value="Submit" >
</form>
<?php echo do_footer(); ?>
Then, here is the php file that processes it to the form.
<?php
require_once("constants.php");
$link = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
mysqli_set_charset($link, 'utf8');
if (!$link) {
die("Database connection failed: " . mysqli_error($link));
}
if (isset($_POST['fname'])) {
$post_vars = array('fname', 'lname', 'eaddress', 'ucomment');
foreach($post_vars as $key) {
$$key = mysqli_real_escape_string($link, $_POST[$key]);
}
$sql = "INSERT INTO comments (fname, lname, eaddress, ucomment) VALUES ('$fname', '$lname', '$eaddress', '$ucomment');";
$result = mysqli_query($link, $sql);
}
mysqli_close($link);
?>
Also, here is my constants file, but I doubt its here since my other forms are posting fine:
<?php
//This is constants.php file
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASSWORD', 'password');
define('DB_NAME', 'conference');
?>