I am trying to code a basic forum system, were an admin types a message and it posts on the "news" page on the website. I set up the "admin panel" where the admins can type their message and send it to the database. However, when I hit submit, it does not show up in phpMyAdmin. I even tried troubleshooting the if statements that check for "blank fields" and "sql errors." Does anyone have any idea why this is?
My text form where the information is entered
<form action="/includes/news_post.php" method="post">
<div class = "container">
<textarea name="message" rows="10" cols="100"></textarea>
<br><br>
<button type="submit" name="news_post" class="postbtn">Post</button>
</div>
</form>
My php code for sending the message to the database.
<?php
if (isset($_POST['news_post'])) {
require 'dbh.inc.php';
$newspost = $_POST['message'];
$uid = $_SESSION['userId'];
if(empty($newspost)) {
header("Location:../admin?error=emptyfield");
exit();
}
else {
$sql = "INSERT INTO news (user_id, post) VALUES (?, ?)";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header ("Location:../admin?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss", $uid, $newspost);
mysqli_stmt_execute($stmt);
header("Location:../admin?news_post=success");
exit();
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
else {
header("Location: ../admin?error=unknown");
exit();
}
?>