I have limited knowledge of php and mysql, I am trying to learn it as I go while creating a very simple CMS from scratch to combine with my PHPBB forum.
The CMS is functional, yet I can only create 1 level of categories. I am failing on having multiple levels of categories, any help would be appreciated.
I have the following columns in categories – cID, Title, Description, Level, Depending. Depending needs to include cID value of the father-category, Level should be +1 to the level value of the father-category.
This is what I have so far with no luck-
The function:
function addCat($cName, $cDesc, $property) {
$property = "$cLevel, $cDepend";
$query = mysql_query("INSERT INTO categories VALUES(null,'$cName','$cDesc', '$cLevel', '$cDepend')") or die(mysql_error());
}
The html for the category selector:
<form action="doAddC.php" method="post">
<td><label for="">Category</label></td>
<td><select name="'CatLevel''CatDepend'">
<?php
$result = mysql_query("SELECT * FROM categories");
while($cat = mysql_fetch_assoc($result)){
?>
<option value="'CatLevel':'<?php echo $cat['Level']; ?>','CatDepend':'<?php echo $cat['cID']; ?>'"><?php echo $cat['Title']; ?></option>
<?php
}
?>
</select></td>
doAddC.php
if(isset($_POST['submit'])) {
if(isset($_POST['CatName'])) {
if(isset($_POST['CatDesc'])) {
addCat($_POST['CatName'], $_POST['CatDesc'], $_POST['CatLevel']['CatDepend']);
header("Location: cats.php");
} else {
echo "Please Add the Category Description!";
include('addCat.php');
}
} else {
echo "Please Set the Category Name!";
include('addCat.php');
}
} else {
header("Location: addCat.php");
}
In the best scenario Level and Depending equal to 0 in the database. I don’t even know where to look for this in manuals.
The problem has been solved. The code for those who might be struggling with a similar problem as follows.
HTML snapshot:
Snapshot of doAddC.php:
Snapshot of function:
Mission accomplished 🙂