Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
utterances-bot opened this issue May 13, 2020 · 6 comments
Open

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

utterances-bot opened this issue May 13, 2020 · 6 comments

Comments

@utterances-bot
Copy link

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

Copy link

ByFeder commented May 13, 2020

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
Copy link
Owner

dcblogdev commented May 13, 2020

you could try wrapping that in an isset

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

    }
}

Copy link

ByFeder commented May 13, 2020

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
Copy link

TraLeeee commented Aug 31, 2020

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 😎

Copy link

vrootz commented Jun 21, 2021

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: dcblogdev/simple-blog-part-4-categories#5

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

Cheers,

Copy link

prslv commented Jul 10, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants