dcblogdev / dcblogcomments

2 stars 0 forks source link

creating-a-blog-from-scratch-with-php-part-4-categories #10

Open utterances-bot opened 4 years ago

utterances-bot commented 4 years ago

Creating a blog from scratch with PHP - Part 4 Categories - DC Blog | Development Tutorials

This part will cover adding categories to posts.

https://dcblog.dev/creating-a-blog-from-scratch-with-php-part-4-categories

ByFeder commented 4 years ago

Trying to access array offset on value of type bool on this line:

if($row3['catID'] == $row2['catID']){

i tried using ?? and ??= but didin't work using them i got all checkbox selected

dcblogdev commented 4 years ago

you could try wrapping that in an isset

if (issset($row3['catID']) && issset($row['catID'])) {
    if($row3['catID'] == $row2['catID']){

    }
}
ByFeder commented 4 years ago

Undefined variable: checked on line: echo "<input type='checkbox' name='catID[]' value='".$row2['catID']."' $checked> ".$row2['catTitle']."
";

And this is how i put the code:

        if (isset($row3['catID']) && isset($row['catID'])) {
            if($row3['catID'] == $row2['catID'])
            {
                $checked = 'checked=checked';
            } else 
            {
                $checked = null;
            }
        }
TraLeeee commented 3 years ago

Undefined variable: checked on line: echo "<input type='checkbox' name='catID[]' value='".$row2['catID']."' $checked> ".$row2['catTitle']." ";

And this is how i put the code:

      if (isset($row3['catID']) && isset($row['catID'])) {
          if($row3['catID'] == $row2['catID'])
          {
              $checked = 'checked=checked';
          } else 
          {
              $checked = null;
          }
      }
                $nums_row = $stmt3->rowCount();
                if ($nums_row > 0 ) {
                    $checked = "checked=checked";
                } else {
                    $checked = null;
                }

This is how i fix this problem in PHP 7.4.9 😎

vrootz commented 3 years ago

Hi, there is a problem with the php code concerning the categories which are not applied to the new/edited posts in the database. Like a user reported here about the issue: https://github.com/dcblogdev/simple-blog-part-4-categories/issues/5

Do you have the time to fix this problem? Would be very nice.

Cheers,

prslv commented 2 years ago

The "blog_post_cats" table doesnt get filled with any info. When I edit a post all categories show this error above them: "Trying to access array offset on value of type bool " because the table is empty in mysql. (I removed that error thanks to @TraLeeee) And when I try to assign a category to a post I click submit and get no errors, but the blog_post_cats table still doesnt get filled. Only if I manually insert for example: postID "5" catID "2" then when I go to Edit the post with ID "5" I see that the category is checked (but still doesnt show up in viewpost.php), when I uncheck and submit the information I manually inserted in the blog_post_cats gets deleted. I guess it should be the other way around. I just recently started making my blog and less than a week ago I converted from html to php so I can have an easier way to post, but I didnt expect this to be such a struggle :D maybe someone who understands can locate where the problem is exactly and fix it