Hi all. I'm having a mad issue... totally mad. I mean I've never had this before.
I have the following HTML form:
<form action="" method="POST" name="createForumCategory">
<label>Create a new category:</label>
<input type="text" name="category" class="m-wrap placeholder-no-fix" />
<input type="hidden" name="id" id="id" value="<?php echo $forumOrange['id']; ?>" />
<button class="btn green" type="submit">Add Category</button>
</form>
That uses the following PHP handler:
if(isset($_SESSION['authenticatedStaff'], $_POST["category"], $_POST["id"])){
$mysqli = mysqli_connect($config['host'], $config['user'], $config['pass'], $config['db']);
$category = $mysqli->real_escape_string($_POST['category']);
$position = "99999";
$query = "INSERT INTO topic_category (id,name,position) VALUES (?, ?, ?)";
$stmt = $mysqli->prepare($query);
$stmt->bind_param('isi', $_POST['id'], $_POST["category"], $position);
$result = $stmt->execute();
$mysqli->close();
}
I know there is no error handling - but there is no need! The reason being is that the form handler doesn't seem to detect any $_POST variables. The HTML form submits and the only thing that changes is the files query string. It changes from localhost/manage.php
to localhost/manage.php?category=test&id=1
(Where test was the value of the category field). So the forms data is being set in the query string, but not processed as per usual.
I could change:
if(isset($_SESSION['authenticatedStaff'], $_POST["category"], $_POST["id"])){
to:
if(isset($_SESSION['authenticatedStaff'], $_GET["category"], $_GET["id"])){
but this is a weak work around and I'd rather try and get to the bottom of why this is occuring in the first place. Any thoughts?
+1 to the individual who spots the magic mistake that I obviously can't.
Thanks in advance,
Michael
N.B. Please ignore the 'unique' blend of procedural and OO code!