I am searching all around the internet but I can't seem to find a simple tutorial that can help me with my custom CMS I am building.
I'd like to add multiple categories to my posts.
For example:
Title: post 1
Content: content goes here
Categories: Technology, Computers, Science, Internet
Title: post 2
Content: content goes here
Categories: Music, Jazz, Classic
So this is what I have to post my articles
My database structure
postID | postTitle | postDesc | postCont | postDate
1 Post 1 info1 content1 date1
2 Post 2 info2 content2 date2
3 Post 3 info2 content3 date3
The FORM
<form action='' method='post'>
<p><label>Title</label><br />
<input type='text' name='postTitle' value='<?php if(isset($error)){ echo $_POST['postTitle'];}?>'></p>
<p><label>Description</label><br />
<textarea name='postDesc' cols='60' rows='10'><?php if(isset($error)){ echo $_POST['postDesc'];}?></textarea></p>
<p><label>Content</label><br />
<textarea name='postCont' cols='60' rows='10'><?php if(isset($error)){ echo $_POST['postCont'];}?></textarea></p>
<p><input type='submit' name='submit' value='Submit'></p>
</form>
the PHP code to place it in the database
//insert into database
$stmt = $db->prepare('INSERT INTO blog_posts (postTitle,postDesc,postCont,postDate) VALUES (:postImage, :postTitle, :postDesc, :postCont, :postDate)') ;
$stmt->execute(array(
':postTitle' => $postTitle,
':postDesc' => $postDesc,
':postCont' => $postCont,
':postDate' => date('Y-m-d H:i:s')
));
//redirect to index page
header('Location: index.php?action=added');
exit;
post_tblit contains all post related data.category_tblit contains all categories with auto_increment ids, thirdpost_cat_rel_tblit contains post id with category id. it may contain multiple rows for single post if there are more than one category. this is one kind of structure. You can modify according to your requirements.