I’m working on a Reddit clone and currently I’m setting up the posts.
The users can have badges (just like on Reddit e.g. premium users have the shield) and I want to check if a user has a badge and display it by using a seperate file but when I try to include this file it just throws an error stating that the file wasn’t there (I already include it in the header and it works just fine there)

Part of the code: echo “<p class=’posts-information’>by <a href=’https://website.com/u/” . $row[‘userid’] . ” ‘>” . $row[‘userid’] . “</a> in <a href=’https://website.com/c/” . $ro[‘community’] . “</a></p>
The badge checking file is supposed to be included after the userid. It includes an SQL statement and a switch case.
given you are only started, here are a few pointers that will help you to help yourself.
Like Linus Torvalds once famously said, “Words are cheap, show me the code”. Do not retell the code. Do not replace the problem code in your question with a story. Post the exact code you have. (Before posting you probably would like to learn how to post a coe on Reddit)
The same goes for the error message. Do not retell it. It;s not an English literature class. Copy and paste the exact error message. It’s an invaluable source of information. Even if you cannot fully make use of it yet, others can. Do not spoil their means to help you
Respect the sub rules before posting, yeah
Just posted it to pastebin
r/PHPhelp
I feared to recieve this comment after I found out that there’s no “question” post flair here…
You might want to see how ur html tags are getting formed in this snippet
echo “……”</a> in < href=’https://website.com/c/” . $ro[‘community’] . “</a></p>
is ur < href= missing an a? < a href=
I typed it on my phone and just missed the a. It’s there and working in the original code.
Includes are relative to the including file (unless you are using an absolute path). Is the header, where it works, in the same directory as the file you are trying to include from?
Yeah.
So I have the index file which includes the header.php and posts.php in the root directory. Header.php and posts.php are in root/inc aswell as the badge-check.php which I’m trying to include.
Relative and absolute paths, in the file system and on the web server.
Protip: you can put your variables in curly braces so it’s easier to read
$string = “hello”; print “{$string} world”;
Hey man!
That’s a big endeavor and I wish you a lot of luck! I realize this is unrelated to what you asked for originally, and I’ll admit – I haven’t looked to see what the exact issue is! I would however like to help you clean up your code a bit. Echoing large strings like that becomes a REAL nightmare REAL fast (TRUST!), so I whipped up a quick gist to help you clean some of that up:
https://gist.github.com/rohjay/a8be087e3f190cebccb6eaaf0f0a6e0f
It’s a templater of sorts… should be pretty self explanatory, but feel free to reach out if you have any questions. That’ll make that code MUCH easier to read and write your HTML with =]

Cheers!
Ryan
PS – I also added a helper method for you to escape your output 😉
Members
Online

source