0

PHP CMS blog adding images with post

Hi, so I have made a CMS blog just barely but it looks pretty nice one thing that is stopping me minus making it secure is finding out how to include images in my blog posts I don't know how to get an image to upload to the database along with the article post so that it wouold share the same id to be retrived and displayed with the post if (isset($_SESSION['logged_in'])){ //display admin page if (isset($_POST['title'], $_POST['content'],$_POST['description'],$_POST['user'],$_POST['category'])){ $title = $_POST['title']; $content = nl2br($_POST['content']); $description = nl2br($_POST['description']); $user = $_POST['user']; $category = $_POST['category']; if(empty($title) or empty($content) or empty($description) or empty($user)){ $error = 'All fields must contain content'; }else{ $query = $pdo->prepare('INSERT INTO articles (article_title, article_content, article_description, article_user, article_category, article_timestamp) VALUES (?,?,?,?,?,?)'); $query->bindValue(1, $title); $query->bindValue(2, $content); $query->bindValue(3, $description); $query->bindValue(4, $user); $query->bindValue(5, $category); $query->bindValue(6, time()); $query->execute(); $posted = 'Posted Congratulations on another finished article!'; } } ?> <form action="add.php" method="post" autocomplete="off"> <input type="text" name="title" placeholder="title" /> <br/><br /> <textarea rows="15"cols="70" placeholder="content" name="content"></textarea> <br /> <br /> <textarea rows="15"cols="70" placeholder="description 155chars" name="description"></textarea> <br /> <br /> <select name="user"> <option value="Ally">Ally</option> <option value="Ed">Ed</option> </select> <select name="category"> <option value="family">Family</option> <option value="business">Business</option> <option value="friends">Friends</option> </select> <input type="submit" value="Add Article" /> <

18th Oct 2018, 10:55 PM
D'Mairis Edwards
D'Mairis Edwards - avatar
3 Respuestas
+ 9
You should create folder to store images, not the SQL.
19th Oct 2018, 12:05 PM
ᴰᴼᴹᴵᴺᴼ
ᴰᴼᴹᴵᴺᴼ - avatar
+ 2
You don't store files in mysql. You store the path to the file. https://www.w3schools.com/php/php_file_upload.asp
18th Oct 2018, 11:01 PM
Toni Isotalo
Toni Isotalo - avatar
0
so the only way to do it is to have to seperate forms one where the file is uploaded to the site and one where the file name in included in a post to be associated with the same id? that is what i have done to make this work and it just seems like a big hassle it also stopped uploading images to the folder after i had uploaded 4 images
19th Oct 2018, 5:10 AM
D'Mairis Edwards
D'Mairis Edwards - avatar