I'm switching over to php prepare statements for a website of mine and I can't seem to get the insert to work. I have no errors back from this, it just doesn't put data into the database. I've followed a video tutorial on this and I've checked for spelling etc and thats all ok, plus the db connection is ok, as it works everywhere else through the site.
PHP:
function insertCategory() {
global $conn;
// Check for submit
if (isset($_POST['submit'])) {
$cat_title_submit = $_POST['cat_title'];
// Check we have a cat title
if ($cat_title_submit == "" || empty($cat_title_submit)) {
echo "The category cannot be blank";
} else {
// Insert Category
$q1stmt = mysqli_prepare($conn, "INSERT INTO categories (cat_title) VALUES (?)");
mysqli_stmt_bind_param($q1stmt, "s", $cat_title_submit);
mysqli_stmt_execute($q1stmt);
// Check query was run
if (!$q1stmt) {
die("Insert Category Failed: ". mysqli_error($conn));
}
}
}
}
HTML:
<!--Add Category-->
<?php insertCategory(); ?>
<div class="col-xs-6">
<form action="" method="post">
<div class="form-group">
<label for="cat_title">Add Category</label>
<input name="cat_title" type="text" class="form-control" />
</div>
<div class="form-group">
<input name="submit" type="submit" class="btn btn-primary" value="Add Category" />
</div>
</form>
</div>