Exception or error:
I have a Table with Columns:
cat_id, cat_name, parent_id
I want to create a page where i can provide the options to add, edit, view and delete categories and Subcategories depending upon each other…
I know how to add categories but i cant add Subcategories with respect to categories. Same is about deleting.
I am using this code to add categories only not sure about the subs:
<?php
if(isset($_POST["Submit"])){
$Category=mysqli_real_escape_string($Connection,$_POST["Category"]);
date_default_timezone_set("Asia/Karachi");
$CurrentTime=time();
$DateTime=strftime("%B - %d, %Y at %H:%M:%S", $CurrentTime);
$DateTime;
$Admin="Sajid Mukhtar";
if(empty($Category)){
$_SESSION["ErrorMessage"]="All Fields must be filled out";
Redirect_to("managecategories.php");
}elseif(strlen($Category)>99){
$_SESSION["ErrorMessage"]="Too long for a category name...";
Redirect_to("managecategories.php");
}else{
global $Connection;
$Query="INSERT INTO category (datetime,name,creatorname) VALUES ('$DateTime','$Category','$Admin')";
$Execute=mysqli_query($Connection,$Query);
if($Execute){
$_SESSION["SuccessMessage"]="Category Added Successfully.";
Redirect_to("managecategories.php");
}else{
$_SESSION["ErrorMessage"]="category failed to Add";
Redirect_to("managecategories.php");
}
}
}
?>
If someone can help me with the code, I will be very grateful…
Just PHP and SQL Code is requested…
Thanks in advance…
Sajid
How to solve: