I am trying to send the input from a user on a form to my database and I am not sure why it isn't going. I have the sql going to my database and all the correct IDs are met so I think it should be working but I am missing something. It may be something in the if(isset part of the code but most likely something in the dropdown portion. Any help would be appreciated.
<?php
session_start();
if(!isset($_SESSION["sess_user"])){
header("location:login.php");
} else {
?>
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="siteCSS.css">
<meta charset="UTF-8">
<title>Recommendations</title>
</head>
<body>
<div id="wrapper">
<header>
<h2>Welcome <?=$_SESSION['sess_user'];?>! <a href="logout.php">Click to Logout</a></h2>
<nav>
<ul>
<li><a href="member.php">Home</a></li>
<li><a href="committees.php">Committees</a></li>
<li><a href="recommendations.php">Recommendations</a></li>
<li><a href="voting.php">Voting</a></li>
</ul>
</nav>
</header>
<h1>Recommendations Main Page</h1>
<form action = "recommendations.php" method="POST">
<br>
<br>
<label>Recommendation ID: </label>
<select name="recommended" required>
<?php
$conn = new mysqli('localhost', 'root', 'root', 'mydb');
if ($conn->connect_error) {
die("Failed: " . $conn->connect_error);
}
$UserID = $_SESSION['sess_userID'];
$selectsql = "select * from user";
echo '<option value="" disabled selected>Choose option</option>';
$result = $conn->query($selectsql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<option value=\"'.$row["UserID"].'">'.$row["UserName"].'</option>';
}
}
?>
</select>
<br>
<br>
<label>Committee ID: </label>
<select name="committee" required>
<?php
$conn = new mysqli('localhost', 'root', 'root', 'mydb');
if ($conn->connect_error) {
die("Failed: " . $conn->connect_error);
}
$selectsql = "select * from committee";
echo '<option value="" disabled selected>Choose option</option>';
$result = $conn->query($selectsql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<option value=\"'.$row["CommitteeID"].'">'.$row["CommitteeName"].'</option>';
}
}
?>
</select>
<br>
<br>
<label>Description (Why they should be recommended):</label>
<input type="text" size = 25 class="textbox" id="RecommendationDescription" name="RecommendationDescription" required>
<br>
<br>
<button type="submit" name="submit">Submit</button>
<?php
if(isset($_POST["submit"])){
if(!empty($_POST['RecommendationDescription'])) {
$recomuser=$_POST['RecommendationID'];
$recommddesc=$_POST['RecommendationDescription'];
$recomcommittee=$_POST['CommitteeID'];
$conn = new mysqli('localhost', 'root', 'root', 'mydb');
if ($conn->connect_error) {
die("Failed: " . $conn->connect_error);
}
$userID = $_SESSION['sess_userID'];
$sql="INSERT INTO mydb.recommendation(RecommendatedID, RecommendationDescription, RecommendationSubmissionDate, UserID, CommitteeID) VALUES('$recomuser', '$recommddesc', CURRENT_TIMESTAMP, '$userID', '$recomcommittee')";
$result = $conn->query($sql);
if($result){
echo "Recommendation Successfully Created";
} else {
echo "Failure!";
}
}
}
?>
</form>
<main>
</main>
</div>
</body>
</html>
<?php
$variable=$_POST['RecommendationName'];
echo $variable;
}
?>