I'm working with PHP to make a Blogging CMS. So here is my code:
if(isset($_POST['insert_blog'])){
$blog_id = uniqid('blog_post');
$blog_author = $_POST['blog_author'];
$blog_title = $_POST['blog_title'];
$blog_body = $_POST['blog_body'];
$blog_tags = $_POST['blog_tags'];
$blog_category = $_POST['blog_category'];
if($blog_title == '' OR $blog_body == '' OR $blog_tags == ''){
echo "
<script>alert('Please fill all the fields!')</script>
exit();
";
}else{
$insert_blog = "
INSERT INTO `blogs` (`blog_id`,`blog_author`,`blog_title`,`blog_body`,`blog_category`,`blog_tags`,`date_posting`)
VALUES ('$blog_id','$blog_author','$blog_title','$blog_body','$blog_category','$blog_tags',NOW())
";
$run_blog = mysqli_query($con2,$insert_blog);
if($run_blog){
echo "<META HTTP-EQUIV='Refresh' Content='0; URL=blognew-homepage.php?blog_id=$blog_id'>";
}else{
error_reporting(E_ALL);
die(mysqli_error($con2));
}
}
}
And I get this error:
Undefined index: blog_author on line 5
Which basically gets the value of this input from the form:
<input class="form-control input-sm" type="text" disabled="disabled" name="blog_author" value="author: <?php echo $dataSet->GetUsername(); ?>">
So as you can see I have set the $dataSet
variable to a method of class which simply gets the username of Admin.
And the other variables passed in manually by user in the form.
(Because they're working fine no need to mention them here)
So why am I getting this error message? Is it wrong to include a method in this form? How to fix this issue?