I made a navigation bar where I store my menus on my webpage.
I created a table for it called categories
, and I managed to add a category to it via a button. I can add everything to it, but if I add something to it, I want to check if it already exists in the categories
table. If it does, then echo 'already exists`. If not, insert the data.
I can't solve this. Thanks for the help.
<?php
function addCategory(){
if(isset($_POST['submit'])){
global $connection;
$cat_title = $_POST['cat_title'];
if($cat_title == "" || empty($cat_title)){
echo "this cannot be blank";
} else {
$query="INSERT INTO categories(cat_title)";// ADD CATEGORIES IN CATEGORIES.PHP //
$query .= "VALUES ('$cat_title')";
$result = mysqli_query($connection,$query);
if(!$result){
die('Query failed' . mysqli_error);
}
}
}
}
?>